| 1 |
""" |
| 2 |
Regression tests for proper working of ForeignKey(null=True). Tests these bugs: |
| 3 |
|
| 4 |
* #7512: including a nullable foreign key reference in Meta ordering has |
| 5 |
unexpected results |
| 6 |
|
| 7 |
""" |
| 8 |
|
| 9 |
from django.db import models |
| 10 |
|
| 11 |
|
| 12 |
# The first two models represent a very simple null FK ordering case. |
| 13 |
class Author(models.Model): |
| 14 |
name = models.CharField(max_length=150) |
| 15 |
|
| 16 |
|
| 17 |
class Article(models.Model): |
| 18 |
title = models.CharField(max_length=150) |
| 19 |
author = models.ForeignKey(Author, models.SET_NULL, null=True) |
| 20 |
|
| 21 |
class Meta: |
| 22 |
ordering = ["author__name"] |
| 23 |
|
| 24 |
|
| 25 |
# These following 4 models represent a far more complex ordering case. |
| 26 |
class SystemInfo(models.Model): |
| 27 |
system_name = models.CharField(max_length=32) |
| 28 |
|
| 29 |
|
| 30 |
class Forum(models.Model): |
| 31 |
system_info = models.ForeignKey(SystemInfo, models.CASCADE) |
| 32 |
forum_name = models.CharField(max_length=32) |
| 33 |
|
| 34 |
|
| 35 |
class Post(models.Model): |
| 36 |
forum = models.ForeignKey(Forum, models.SET_NULL, null=True) |
| 37 |
title = models.CharField(max_length=32) |
| 38 |
|
| 39 |
|
| 40 |
class Comment(models.Model): |
| 41 |
post = models.ForeignKey(Post, models.SET_NULL, null=True) |
| 42 |
comment_text = models.CharField(max_length=250) |
| 43 |
|
| 44 |
class Meta: |
| 45 |
ordering = ["post__forum__system_info__system_name", "comment_text"] |