PageRenderTime 72ms CodeModel.GetById 66ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/testproject/issue_29/models.py

http://django-multilingual.googlecode.com/
Python | 42 lines | 34 code | 0 blank | 8 comment | 0 complexity | 9364874f1378a955d223e0157757d968 MD5 | raw file
 1"""
 2Models and unit tests for issues reported in the tracker.
 3
 4>>> from multilingual import set_default_language
 5
 6# test for issue #15
 7# http://code.google.com/p/django-multilingual/issues/detail?id=15
 8
 9>>> set_default_language('pl')
10>>> g = Gallery.objects.create(id=2, title_pl='Test polski', title_en='English Test')
11>>> g.title
12'Test polski'
13>>> g.title_en
14'English Test'
15>>> g.save()
16>>> g.title_en = 'Test polski'
17>>> g.save()
18>>> try:
19...     g = Gallery.objects.create(id=3, title_pl='Test polski')
20... except: print "ERROR"
21... 
22ERROR
23>>> 
24"""
25
26from django.db import models
27import multilingual
28try:
29    from django.utils.translation import ugettext as _
30except ImportError:
31    pass
32
33class Gallery(models.Model):
34    class Admin:
35        pass
36    ref = models.ForeignKey('self', verbose_name=_('Parent gallery'),
37                            blank=True, null=True)
38    modified = models.DateField(_('Modified'), auto_now=True)
39
40    class Translation(multilingual.Translation):
41        title = models.CharField(_('Title'), max_length=50, unique = True)
42        description = models.TextField(_('Description'), blank=True)