mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 13:04:03 +03:00
unique_for_month, unique_for_year
This commit is contained in:
parent
ae53fdff9c
commit
f9c0e6ee1b
|
@ -24,7 +24,8 @@ from rest_framework.utils.field_mapping import (
|
|||
ClassLookupDict
|
||||
)
|
||||
from rest_framework.validators import (
|
||||
UniqueForDateValidator, UniqueTogetherValidator
|
||||
UniqueForDateValidator, UniqueForMonthValidator, UniqueForYearValidator,
|
||||
UniqueTogetherValidator
|
||||
)
|
||||
import copy
|
||||
import inspect
|
||||
|
@ -601,6 +602,22 @@ class ModelSerializer(Serializer):
|
|||
)
|
||||
validators.append(validator)
|
||||
|
||||
if field.unique_for_month and field_name in field_names:
|
||||
validator = UniqueForMonthValidator(
|
||||
queryset=model_class._default_manager,
|
||||
field=field_name,
|
||||
date_field=field.unique_for_month
|
||||
)
|
||||
validators.append(validator)
|
||||
|
||||
if field.unique_for_year and field_name in field_names:
|
||||
validator = UniqueForYearValidator(
|
||||
queryset=model_class._default_manager,
|
||||
field=field_name,
|
||||
date_field=field.unique_for_year
|
||||
)
|
||||
validators.append(validator)
|
||||
|
||||
return validators
|
||||
|
||||
def _get_base_fields(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user