diff options
Diffstat (limited to 'tests/distinct_on_fields/models.py')
-rw-r--r-- | tests/distinct_on_fields/models.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/distinct_on_fields/models.py b/tests/distinct_on_fields/models.py index 053fd9cc5f..2c33f3ad80 100644 --- a/tests/distinct_on_fields/models.py +++ b/tests/distinct_on_fields/models.py @@ -7,8 +7,13 @@ from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Tag(models.Model): name = models.CharField(max_length=10) - parent = models.ForeignKey('self', blank=True, null=True, - related_name='children') + parent = models.ForeignKey( + 'self', + models.SET_NULL, + blank=True, + null=True, + related_name='children', + ) class Meta: ordering = ['name'] @@ -20,14 +25,19 @@ class Tag(models.Model): @python_2_unicode_compatible class Celebrity(models.Model): name = models.CharField("Name", max_length=20) - greatest_fan = models.ForeignKey("Fan", null=True, unique=True) + greatest_fan = models.ForeignKey( + "Fan", + models.SET_NULL, + null=True, + unique=True, + ) def __str__(self): return self.name class Fan(models.Model): - fan_of = models.ForeignKey(Celebrity) + fan_of = models.ForeignKey(Celebrity, models.CASCADE) @python_2_unicode_compatible @@ -44,8 +54,8 @@ class Staff(models.Model): @python_2_unicode_compatible class StaffTag(models.Model): - staff = models.ForeignKey(Staff) - tag = models.ForeignKey(Tag) + staff = models.ForeignKey(Staff, models.CASCADE) + tag = models.ForeignKey(Tag, models.CASCADE) def __str__(self): return "%s -> %s" % (self.tag, self.staff) |