mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge f98d487931
into 7fd4f7e2ff
This commit is contained in:
commit
daad246fa8
|
@ -592,13 +592,15 @@ class ModelSerializer(Serializer):
|
||||||
# Note that we make sure to check `unique_together` both on the
|
# Note that we make sure to check `unique_together` both on the
|
||||||
# base model class, but also on any parent classes.
|
# base model class, but also on any parent classes.
|
||||||
for parent_class in [model_class] + list(model_class._meta.parents.keys()):
|
for parent_class in [model_class] + list(model_class._meta.parents.keys()):
|
||||||
for unique_together in parent_class._meta.unique_together:
|
http_method = getattr(self.context.get('request'), 'method', None)
|
||||||
if field_names.issuperset(set(unique_together)):
|
if http_method and http_method != 'PATCH':
|
||||||
validator = UniqueTogetherValidator(
|
for unique_together in parent_class._meta.unique_together:
|
||||||
queryset=parent_class._default_manager,
|
if field_names.issuperset(set(unique_together)):
|
||||||
fields=unique_together
|
validator = UniqueTogetherValidator(
|
||||||
)
|
queryset=parent_class._default_manager,
|
||||||
validators.append(validator)
|
fields=unique_together
|
||||||
|
)
|
||||||
|
validators.append(validator)
|
||||||
|
|
||||||
# Add any unique_for_date/unique_for_month/unique_for_year constraints.
|
# Add any unique_for_date/unique_for_month/unique_for_year constraints.
|
||||||
info = model_meta.get_field_info(model_class)
|
info = model_meta.get_field_info(model_class)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user