mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #35580 -- Allowed related fields referencing auto-created through models.
This commit is contained in:
parent
759abc4daf
commit
af84bcc8d1
@ -187,7 +187,9 @@ class RelatedField(FieldCacheMixin, Field):
|
|||||||
return errors
|
return errors
|
||||||
|
|
||||||
def _check_relation_model_exists(self):
|
def _check_relation_model_exists(self):
|
||||||
rel_is_missing = self.remote_field.model not in self.opts.apps.get_models()
|
rel_is_missing = self.remote_field.model not in self.opts.apps.get_models(
|
||||||
|
include_auto_created=True
|
||||||
|
)
|
||||||
rel_is_string = isinstance(self.remote_field.model, str)
|
rel_is_string = isinstance(self.remote_field.model, str)
|
||||||
model_name = (
|
model_name = (
|
||||||
self.remote_field.model
|
self.remote_field.model
|
||||||
|
@ -89,6 +89,23 @@ class RelativeFieldTests(SimpleTestCase):
|
|||||||
field = Model._meta.get_field("m2m")
|
field = Model._meta.get_field("m2m")
|
||||||
self.assertEqual(field.check(from_model=Model), [])
|
self.assertEqual(field.check(from_model=Model), [])
|
||||||
|
|
||||||
|
@isolate_apps("invalid_models_tests")
|
||||||
|
def test_auto_created_through_model(self):
|
||||||
|
class OtherModel(models.Model):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class M2MModel(models.Model):
|
||||||
|
many_to_many_rel = models.ManyToManyField(OtherModel)
|
||||||
|
|
||||||
|
class O2OModel(models.Model):
|
||||||
|
one_to_one_rel = models.OneToOneField(
|
||||||
|
"invalid_models_tests.M2MModel_many_to_many_rel",
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
|
||||||
|
field = O2OModel._meta.get_field("one_to_one_rel")
|
||||||
|
self.assertEqual(field.check(from_model=O2OModel), [])
|
||||||
|
|
||||||
def test_many_to_many_with_useless_options(self):
|
def test_many_to_many_with_useless_options(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
|
Loading…
Reference in New Issue
Block a user