mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #32676 -- Prevented migrations from rendering related field attributes when not passed during initialization.
Thanks Simon Charette for the implementation idea.
This commit is contained in:
committed by
Mariusz Felisiak
parent
b746596f5f
commit
b9df2b74b9
@@ -432,6 +432,34 @@ class FieldDeconstructionTests(SimpleTestCase):
|
||||
self.assertEqual(kwargs, {"to": "auth.Permission"})
|
||||
self.assertEqual(kwargs['to'].setting_name, "AUTH_USER_MODEL")
|
||||
|
||||
def test_many_to_many_field_related_name(self):
|
||||
class MyModel(models.Model):
|
||||
flag = models.BooleanField(default=True)
|
||||
m2m = models.ManyToManyField('self')
|
||||
m2m_related_name = models.ManyToManyField(
|
||||
'self',
|
||||
related_name='custom_name',
|
||||
related_query_name='custom_query_name',
|
||||
limit_choices_to={'flag': True},
|
||||
)
|
||||
|
||||
name, path, args, kwargs = MyModel.m2m.field.deconstruct()
|
||||
self.assertEqual(path, 'django.db.models.ManyToManyField')
|
||||
self.assertEqual(args, [])
|
||||
# deconstruct() should not include attributes which were not passed to
|
||||
# the field during initialization.
|
||||
self.assertEqual(kwargs, {'to': 'field_deconstruction.MyModel'})
|
||||
# Passed attributes.
|
||||
name, path, args, kwargs = MyModel.m2m_related_name.field.deconstruct()
|
||||
self.assertEqual(path, 'django.db.models.ManyToManyField')
|
||||
self.assertEqual(args, [])
|
||||
self.assertEqual(kwargs, {
|
||||
'to': 'field_deconstruction.MyModel',
|
||||
'related_name': 'custom_name',
|
||||
'related_query_name': 'custom_query_name',
|
||||
'limit_choices_to': {'flag': True},
|
||||
})
|
||||
|
||||
def test_positive_integer_field(self):
|
||||
field = models.PositiveIntegerField()
|
||||
name, path, args, kwargs = field.deconstruct()
|
||||
|
||||
Reference in New Issue
Block a user