diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-01-16 08:06:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-16 08:06:16 +0100 |
| commit | bf77669453b9e9f64291da6701fe06fd5ba47e29 (patch) | |
| tree | a2d13e239a715418a699979ad080c01beba62819 /tests/invalid_models_tests/test_relative_fields.py | |
| parent | 7400da49a5d0ec5a087c3cf05e0b2d15048fc93f (diff) | |
Fixed #29998 -- Allowed multiple OneToOneFields to the parent model.
We assumed that any OneToOneField's in a child model must be the
parent link and raised an error when parent_link=True was not
specified. This patch allows to specify multiple OneToOneField's to
the parent model.
OneToOneField's without a custom related_name will raise fields.E304
and fields.E305 so this should warn users when they try to override
the auto-created OneToOneField.
Diffstat (limited to 'tests/invalid_models_tests/test_relative_fields.py')
| -rw-r--r-- | tests/invalid_models_tests/test_relative_fields.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_relative_fields.py b/tests/invalid_models_tests/test_relative_fields.py index 4ac0c547a9..786573672f 100644 --- a/tests/invalid_models_tests/test_relative_fields.py +++ b/tests/invalid_models_tests/test_relative_fields.py @@ -1291,6 +1291,33 @@ class ComplexClashTests(SimpleTestCase): ), ]) + def test_clash_parent_link(self): + class Parent(models.Model): + pass + + class Child(Parent): + other_parent = models.OneToOneField(Parent, models.CASCADE) + + errors = [ + ('fields.E304', 'accessor', 'parent_ptr', 'other_parent'), + ('fields.E305', 'query name', 'parent_ptr', 'other_parent'), + ('fields.E304', 'accessor', 'other_parent', 'parent_ptr'), + ('fields.E305', 'query name', 'other_parent', 'parent_ptr'), + ] + self.assertEqual(Child.check(), [ + Error( + "Reverse %s for 'Child.%s' clashes with reverse %s for " + "'Child.%s'." % (attr, field_name, attr, clash_name), + hint=( + "Add or change a related_name argument to the definition " + "for 'Child.%s' or 'Child.%s'." % (field_name, clash_name) + ), + obj=Child._meta.get_field(field_name), + id=error_id, + ) + for error_id, attr, field_name, clash_name in errors + ]) + @isolate_apps('invalid_models_tests') class M2mThroughFieldsTests(SimpleTestCase): |
