mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 22:04:48 +03:00
Do not add uniquness_extra_kwargs when validators are explicitly declared.
This commit is contained in:
parent
85c7a15c62
commit
3e45e1e8b0
|
@ -1263,6 +1263,9 @@ class ModelSerializer(Serializer):
|
|||
|
||||
('dict of updated extra kwargs', 'mapping of hidden fields')
|
||||
"""
|
||||
if getattr(self.Meta, 'validators', None) is not None:
|
||||
return (extra_kwargs, {})
|
||||
|
||||
model = getattr(self.Meta, 'model')
|
||||
model_fields = self._get_model_fields(
|
||||
field_names, declared_fields, extra_kwargs
|
||||
|
@ -1313,7 +1316,7 @@ class ModelSerializer(Serializer):
|
|||
else:
|
||||
uniqueness_extra_kwargs[unique_constraint_name] = {'default': default}
|
||||
elif default is not empty:
|
||||
# The corresponding field is not present in the,
|
||||
# The corresponding field is not present in the
|
||||
# serializer. We have a default to use for it, so
|
||||
# add in a hidden field that populates it.
|
||||
hidden_fields[unique_constraint_name] = HiddenField(default=default)
|
||||
|
|
|
@ -261,7 +261,7 @@ class TestUniquenessTogetherValidation(TestCase):
|
|||
|
||||
def test_allow_explict_override(self):
|
||||
"""
|
||||
Ensure unique_together can be explicitly removed
|
||||
Ensure validators can be explicitly removed..
|
||||
"""
|
||||
class NoValidatorsSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
@ -273,8 +273,8 @@ class TestUniquenessTogetherValidation(TestCase):
|
|||
expected = dedent("""
|
||||
NoValidatorsSerializer():
|
||||
id = IntegerField(label='ID', read_only=True)
|
||||
race_name = CharField(max_length=100, required=True)
|
||||
position = IntegerField(required=True)
|
||||
race_name = CharField(max_length=100)
|
||||
position = IntegerField()
|
||||
""")
|
||||
assert repr(serializer) == expected
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user