Ticket #11283: models.py

File models.py, 744 bytes (added by benmoran, 15 years ago)
Line 
1from django.db import models
2
3class Article(models.Model):
4 headline = models.CharField(max_length=100, default='Default headline')
5 pub_date = models.DateTimeField()
6
7 def __unicode__(self):
8 return self.headline
9
10__test__ = {'API_TESTS': """
11>>> from datetime import datetime
12>>> a = Article(id=None, headline='Outside of a dog, a book is Man''s best friend', pub_date=datetime(2005, 7, 28))
13>>> a.save()
14>>> a2 = Article(id=None, headline='and inside of a dog, it''s too dark to read', pub_date=datetime(2006,7,28))
15>>> a2.save()
16
17# The latest id should be 2
18>>> Article.objects.latest('id').id
192
20
21# The latest id is still 2, even if we sorted the queryset first.
22>>> Article.objects.order_by('id').latest('id').id
232
24
25"""}
26
Back to Top