PageRenderTime 141ms CodeModel.GetById 137ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/null_fk_ordering/models.py

https://code.google.com/p/mango-py/
Python | 49 lines | 27 code | 13 blank | 9 comment | 0 complexity | 459c21ee1f3437f7c98d8976e9d6ee34 MD5 | raw file
 1"""
 2Regression tests for proper working of ForeignKey(null=True). Tests these bugs:
 3
 4    * #7512: including a nullable foreign key reference in Meta ordering has un
 5xpected results
 6
 7"""
 8
 9from django.db import models
10
11# The first two models represent a very simple null FK ordering case.
12class Author(models.Model):
13    name = models.CharField(max_length=150)
14
15class Article(models.Model):
16    title = models.CharField(max_length=150)
17    author = models.ForeignKey(Author, null=True)
18
19    def __unicode__(self):
20        return u'Article titled: %s' % (self.title, )
21
22    class Meta:
23        ordering = ['author__name', ]
24
25
26# These following 4 models represent a far more complex ordering case.
27class SystemInfo(models.Model):
28    system_name = models.CharField(max_length=32)
29
30class Forum(models.Model):
31    system_info = models.ForeignKey(SystemInfo)
32    forum_name = models.CharField(max_length=32)
33
34class Post(models.Model):
35    forum = models.ForeignKey(Forum, null=True)
36    title = models.CharField(max_length=32)
37
38    def __unicode__(self):
39        return self.title
40
41class Comment(models.Model):
42    post = models.ForeignKey(Post, null=True)
43    comment_text = models.CharField(max_length=250)
44
45    class Meta:
46        ordering = ['post__forum__system_info__system_name', 'comment_text']
47
48    def __unicode__(self):
49        return self.comment_text