mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-05-22 21:46:08 +03:00
Use datetime example for the Field.initial
attribute
Just like regular Django fields, the example adopted uses a `datetiume.date.today` to illustrate the functionality.
This commit is contained in:
parent
908efd6656
commit
a32baeab0c
|
@ -84,10 +84,10 @@ A text string that may be used as a description of the field in HTML form fields
|
||||||
A value that should be used for pre-populating the value of HTML form fields. You may pass a callable to it, just as
|
A value that should be used for pre-populating the value of HTML form fields. You may pass a callable to it, just as
|
||||||
you may do with any regular Django `Field`:
|
you may do with any regular Django `Field`:
|
||||||
|
|
||||||
def user_default_color():
|
import datetime
|
||||||
return 'blue'
|
from rest_framework import serializers
|
||||||
|
class ExampleSerializer(serializers.Serializer):
|
||||||
color = serializers.CharField(initial=user_default_color)
|
day = serializers.DateField(initial=datetime.date.today)
|
||||||
|
|
||||||
### `style`
|
### `style`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user