mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #21127 -- Started deprecation toward requiring on_delete for ForeignKey/OneToOneField
This commit is contained in:
committed by
Tim Graham
parent
87d55081ea
commit
c2e70f0265
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user