| | 393 | |
|---|
| | 394 | # Create another Article class to test __year queries on a DateField. |
|---|
| | 395 | class Article2(models.Model): |
|---|
| | 396 | headline = models.CharField(max_length=100, default='No title given.') |
|---|
| | 397 | pub_date = models.DateField() |
|---|
| | 398 | |
|---|
| | 399 | class Meta: |
|---|
| | 400 | ordering = ('pub_date', 'headline') |
|---|
| | 401 | |
|---|
| | 402 | def __unicode__(self): |
|---|
| | 403 | return self.headline |
|---|
| | 404 | __test__['API_TESTS'] += """ |
|---|
| | 405 | |
|---|
| | 406 | # Edge-case test: A year lookup on a DateField should retrieve all |
|---|
| | 407 | # objects in the give year, including Jan. 1 and Dec. 31. |
|---|
| | 408 | >>> from datetime import date |
|---|
| | 409 | >>> a2_1 = Article2.objects.create(headline='Article2 1', pub_date=date(2008, 1, 1)) |
|---|
| | 410 | >>> a2_2 = Article2.objects.create(headline='Article2 2', pub_date=date(2008, 12, 31)) |
|---|
| | 411 | >>> Article2.objects.filter(pub_date__year=2008) |
|---|
| | 412 | [<Article2: Article2 1>, <Article2: Article2 2>] |
|---|
| | 413 | """ |