mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-07 13:54:45 +03:00
Add imports in validators docs (#4355)
This commit is contained in:
parent
a9a097496e
commit
54096dc22f
|
@ -64,6 +64,8 @@ It takes a single required argument, and an optional `messages` argument:
|
||||||
|
|
||||||
This validator should be applied to *serializer fields*, like so:
|
This validator should be applied to *serializer fields*, like so:
|
||||||
|
|
||||||
|
from rest_framework.validators import UniqueValidator
|
||||||
|
|
||||||
slug = SlugField(
|
slug = SlugField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
validators=[UniqueValidator(queryset=BlogPost.objects.all())]
|
validators=[UniqueValidator(queryset=BlogPost.objects.all())]
|
||||||
|
@ -80,6 +82,8 @@ It has two required arguments, and a single optional `messages` argument:
|
||||||
|
|
||||||
The validator should be applied to *serializer classes*, like so:
|
The validator should be applied to *serializer classes*, like so:
|
||||||
|
|
||||||
|
from rest_framework.validators import UniqueTogetherValidator
|
||||||
|
|
||||||
class ExampleSerializer(serializers.Serializer):
|
class ExampleSerializer(serializers.Serializer):
|
||||||
# ...
|
# ...
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -114,6 +118,8 @@ These validators can be used to enforce the `unique_for_date`, `unique_for_month
|
||||||
|
|
||||||
The validator should be applied to *serializer classes*, like so:
|
The validator should be applied to *serializer classes*, like so:
|
||||||
|
|
||||||
|
from rest_framework.validators import UniqueForYearValidator
|
||||||
|
|
||||||
class ExampleSerializer(serializers.Serializer):
|
class ExampleSerializer(serializers.Serializer):
|
||||||
# ...
|
# ...
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -183,7 +189,7 @@ It takes a single argument, which is the default value or callable that should b
|
||||||
|
|
||||||
created_at = serializers.DateTimeField(
|
created_at = serializers.DateTimeField(
|
||||||
read_only=True,
|
read_only=True,
|
||||||
default=CreateOnlyDefault(timezone.now)
|
default=serializers.CreateOnlyDefault(timezone.now)
|
||||||
)
|
)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue
Block a user