Advertisement
wheeler

django - tmnd

Oct 19th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. # blog/models.py
  2.  
  3. from django.db import models
  4. from django.utils.translation import ugettext_lazy as _
  5.  
  6. class PostCategory(models.Model):
  7.     name = models.CharField(max_length=35)
  8.  
  9.     def __str__(self):
  10.         return self.name
  11.  
  12.     class Meta:
  13.         verbose_name = _('Posts\' category')
  14.         verbose_name_plural = _('Posts\' categories')
  15.  
  16. class Post(models.Model):
  17.     title = models.CharField(_('Title'), max_length=200)
  18.     content = models.TextField(_('Content'))
  19.     category = models.ForeignKey(PostCategory)
  20.     pub_date = models.DateTimeField(_('Publication date'))
  21.     published = models.BooleanField(_('Is published?'), default=False)
  22.  
  23.     def __str__(self):
  24.         return self.title
  25.  
  26.     class Meta:
  27.         verbose_name = _('Post')
  28.         verbose_name_plural = _('Posts')
  29.  
  30.  
  31. # blog/views.py
  32.  
  33. from django.shortcuts import render
  34. from django.http import HttpResponse
  35. from django.utils.translation import ugettext as _
  36. from django.utils import translation
  37.  
  38. def index(request):
  39.     translation.activate("pl_PL")
  40.     output = _('Posts') + '<br/>'
  41.     output += translation.get_language()
  42.     return HttpResponse(output)
  43.  
  44. # excerpt from settings.py
  45.  
  46. LANGUAGE_CODE = 'pl_PL'
  47.  
  48. TIME_ZONE = 'Europe/Warsaw'
  49.  
  50. USE_I18N = True
  51.  
  52. USE_L10N = True
  53.  
  54. USE_TZ = True
  55.  
  56. LANGUAGES = (
  57.     ('pl', _('Polish')),
  58.     ('en', _('English')),
  59. )
  60.  
  61. LOCALE_PATHS = (
  62.     '/var/www/tmnd/locale/'
  63. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement