Commit 54096dc2 by Corentin Smith Committed by Tom Christie

Add imports in validators docs (#4355)

parent a9a09749
...@@ -64,6 +64,8 @@ It takes a single required argument, and an optional `messages` argument: ...@@ -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: ...@@ -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 ...@@ -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 ...@@ -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)
) )
--- ---
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment