Specify on_delete argument for all related fields that need it
parent
298460c4cf
commit
1e7237986c
|
|
@ -37,8 +37,10 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||||
|
|
||||||
# avoid ContentType related field accessor clash (an error emitted by model validation)
|
# avoid ContentType related field accessor clash (an error emitted by model validation)
|
||||||
#: The model field that stores the :class:`~django.contrib.contenttypes.models.ContentType` reference to the actual class.
|
#: The model field that stores the :class:`~django.contrib.contenttypes.models.ContentType` reference to the actual class.
|
||||||
polymorphic_ctype = models.ForeignKey(ContentType, null=True, editable=False,
|
polymorphic_ctype = models.ForeignKey(
|
||||||
related_name='polymorphic_%(app_label)s.%(class)s_set+')
|
ContentType, null=True, editable=False, on_delete=models.CASCADE,
|
||||||
|
related_name='polymorphic_%(app_label)s.%(class)s_set+'
|
||||||
|
)
|
||||||
|
|
||||||
# some applications want to know the name of the fields that are added to its models
|
# some applications want to know the name of the fields that are added to its models
|
||||||
polymorphic_internal_model_fields = ['polymorphic_ctype']
|
polymorphic_internal_model_fields = ['polymorphic_ctype']
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
||||||
|
|
||||||
class RelationBase(ShowFieldTypeAndContent, PolymorphicModel):
|
class RelationBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
field_base = models.CharField(max_length=10)
|
field_base = models.CharField(max_length=10)
|
||||||
fk = models.ForeignKey('self', null=True, related_name='relationbase_set')
|
fk = models.ForeignKey('self', on_delete=models.CASCADE, null=True, related_name='relationbase_set')
|
||||||
m2m = models.ManyToManyField('self')
|
m2m = models.ManyToManyField('self')
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -128,7 +128,7 @@ class RelatingModel(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class One2OneRelatingModel(PolymorphicModel):
|
class One2OneRelatingModel(PolymorphicModel):
|
||||||
one2one = models.OneToOneField(Model2A)
|
one2one = models.OneToOneField(Model2A, on_delete=models.CASCADE)
|
||||||
field1 = models.CharField(max_length=10)
|
field1 = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -142,7 +142,7 @@ class ModelUnderRelParent(PolymorphicModel):
|
||||||
|
|
||||||
|
|
||||||
class ModelUnderRelChild(PolymorphicModel):
|
class ModelUnderRelChild(PolymorphicModel):
|
||||||
parent = models.ForeignKey(ModelUnderRelParent, related_name='children')
|
parent = models.ForeignKey(ModelUnderRelParent, on_delete=models.CASCADE, related_name='children')
|
||||||
_private2 = models.CharField(max_length=10)
|
_private2 = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -208,7 +208,7 @@ class ParentModelWithManager(PolymorphicModel):
|
||||||
|
|
||||||
class ChildModelWithManager(PolymorphicModel):
|
class ChildModelWithManager(PolymorphicModel):
|
||||||
# Also test whether foreign keys receive the manager:
|
# Also test whether foreign keys receive the manager:
|
||||||
fk = models.ForeignKey(ParentModelWithManager, related_name='childmodel_set')
|
fk = models.ForeignKey(ParentModelWithManager, on_delete=models.CASCADE, related_name='childmodel_set')
|
||||||
objects = MyManager()
|
objects = MyManager()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -232,7 +232,7 @@ class PlainParentModelWithManager(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class PlainChildModelWithManager(models.Model):
|
class PlainChildModelWithManager(models.Model):
|
||||||
fk = models.ForeignKey(PlainParentModelWithManager, related_name='childmodel_set')
|
fk = models.ForeignKey(PlainParentModelWithManager, on_delete=models.CASCADE, related_name='childmodel_set')
|
||||||
objects = PlainMyManager()
|
objects = PlainMyManager()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -264,12 +264,12 @@ class BlogB(BlogBase):
|
||||||
|
|
||||||
|
|
||||||
class BlogEntry(ShowFieldTypeAndContent, PolymorphicModel):
|
class BlogEntry(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
blog = models.ForeignKey(BlogA)
|
blog = models.ForeignKey(BlogA, on_delete=models.CASCADE)
|
||||||
text = models.CharField(max_length=10)
|
text = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
class BlogEntry_limit_choices_to(ShowFieldTypeAndContent, PolymorphicModel):
|
class BlogEntry_limit_choices_to(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
blog = models.ForeignKey(BlogBase)
|
blog = models.ForeignKey(BlogBase, on_delete=models.CASCADE)
|
||||||
text = models.CharField(max_length=10)
|
text = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -375,13 +375,15 @@ class ProxyModelB(ProxyModelBase):
|
||||||
# with related field 'ContentType.relatednameclash_set'." (reported by Andrew Ingram)
|
# with related field 'ContentType.relatednameclash_set'." (reported by Andrew Ingram)
|
||||||
# fixed with related_name
|
# fixed with related_name
|
||||||
class RelatedNameClash(ShowFieldType, PolymorphicModel):
|
class RelatedNameClash(ShowFieldType, PolymorphicModel):
|
||||||
ctype = models.ForeignKey(ContentType, null=True, editable=False)
|
ctype = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True, editable=False)
|
||||||
|
|
||||||
# class with a parent_link to superclass, and a related_name back to subclass
|
# class with a parent_link to superclass, and a related_name back to subclass
|
||||||
|
|
||||||
|
|
||||||
class TestParentLinkAndRelatedName(ModelShow1_plain):
|
class TestParentLinkAndRelatedName(ModelShow1_plain):
|
||||||
superclass = models.OneToOneField(ModelShow1_plain, parent_link=True, related_name='related_name_subclass')
|
superclass = models.OneToOneField(
|
||||||
|
ModelShow1_plain, on_delete=models.CASCADE, parent_link=True, related_name='related_name_subclass'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CustomPkBase(ShowFieldTypeAndContent, PolymorphicModel):
|
class CustomPkBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue