59
56
return 'Názov: %s' % self.name
62
__test__ = {'API_TESTS': """
63
(NOTE: Part of the regression test here is merely parsing the model
64
declaration. The verbose_name, in particular, did not always work.)
66
An empty choice field should return None for the display name.
68
>>> from datetime import datetime
69
>>> a = Article(headline="Look at me!", pub_date=datetime.now())
71
>>> a.get_status_display() is None
74
Empty strings should be returned as Unicode
75
>>> a2 = Article.objects.get(pk=a.id)
79
# TextFields can hold more than 4000 characters (this was broken in Oracle).
80
>>> a3 = Article(headline="Really, really big", pub_date=datetime.now())
81
>>> a3.article_text = "ABCDE" * 1000
83
>>> a4 = Article.objects.get(pk=a3.id)
84
>>> len(a4.article_text)
87
# Regression test for #659
89
>>> p = Party.objects.create(when = datetime.datetime(1999, 12, 31))
90
>>> p = Party.objects.create(when = datetime.datetime(1998, 12, 31))
91
>>> p = Party.objects.create(when = datetime.datetime(1999, 1, 1))
92
>>> [p.when for p in Party.objects.filter(when__month=2)]
94
>>> [p.when for p in Party.objects.filter(when__month=1)]
95
[datetime.date(1999, 1, 1)]
96
>>> [p.when for p in Party.objects.filter(when__month=12)]
97
[datetime.date(1999, 12, 31), datetime.date(1998, 12, 31)]
98
>>> [p.when for p in Party.objects.filter(when__year=1998)]
99
[datetime.date(1998, 12, 31)]
101
# Regression test for #8510
102
>>> [p.when for p in Party.objects.filter(when__day='31')]
103
[datetime.date(1999, 12, 31), datetime.date(1998, 12, 31)]
104
>>> [p.when for p in Party.objects.filter(when__month='12')]
105
[datetime.date(1999, 12, 31), datetime.date(1998, 12, 31)]
106
>>> [p.when for p in Party.objects.filter(when__year='1998')]
107
[datetime.date(1998, 12, 31)]
109
# Date filtering was failing with NULL date values in SQLite (regression test
110
# for #3501, amongst other things).
111
>>> _ = Party.objects.create()
112
>>> p = Party.objects.filter(when__month=1)[0]
114
datetime.date(1999, 1, 1)
115
>>> l = Party.objects.filter(pk=p.pk).dates("when", "month")
119
# Check that get_next_by_FIELD and get_previous_by_FIELD don't crash when we
120
# have usecs values stored on the database
122
# [It crashed after the Field.get_db_prep_* refactor, because on most backends
123
# DateTimeFields supports usecs, but DateTimeField.to_python didn't recognize
124
# them. (Note that Model._get_next_or_previous_by_FIELD coerces values to
127
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 16, 0, 0))
128
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 6, 1, 1))
129
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 13, 1, 1))
130
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 12, 0, 20, 24))
131
>>> e.get_next_by_when().when
132
datetime.datetime(2000, 1, 1, 13, 1, 1)
133
>>> e.get_previous_by_when().when
134
datetime.datetime(2000, 1, 1, 6, 1, 1)
136
# Check Department and Worker
137
>>> d = Department(id=10, name='IT')
139
>>> w = Worker(department=d, name='Full-time')
144
# Models with broken unicode methods should still have a printable repr
145
>>> b = BrokenUnicodeMethod(name="Jerry")
147
>>> BrokenUnicodeMethod.objects.all()
148
[<BrokenUnicodeMethod: [Bad Unicode data]>]
152
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] not in (
153
"django.db.backends.mysql",
154
"django.db.backends.oracle"):
155
__test__["timezone-tests"] = """
156
# Saving an updating with timezone-aware datetime Python objects. Regression
159
# The idea is that all these creations and saving should work without crashing.
160
# It's not rocket science.
161
>>> Article.objects.all().delete()
162
>>> dt1 = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(600))
163
>>> dt2 = datetime.datetime(2008, 8, 31, 17, 20, tzinfo=tzinfo.FixedOffset(600))
164
>>> obj = Article.objects.create(headline="A headline", pub_date=dt1, article_text="foo")
166
>>> obj.pub_date = dt2
168
>>> Article.objects.filter(headline="A headline").update(pub_date=dt1)
58
class NonAutoPK(models.Model):
59
name = models.CharField(max_length=10, primary_key=True)