mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 13:00:12 +03:00
Add 'default' value in metadatas
This commit is contained in:
parent
2d27d9a10a
commit
4c3071b97f
|
@ -15,6 +15,7 @@ from django.http import Http404
|
|||
from django.utils.encoding import force_text
|
||||
|
||||
from rest_framework import exceptions, serializers
|
||||
from rest_framework.fields import empty
|
||||
from rest_framework.request import clone_request
|
||||
from rest_framework.utils.field_mapping import ClassLookupDict
|
||||
|
||||
|
@ -123,13 +124,13 @@ class SimpleMetadata(BaseMetadata):
|
|||
|
||||
attrs = [
|
||||
'read_only', 'label', 'help_text',
|
||||
'min_length', 'max_length',
|
||||
'min_length', 'max_length', 'default',
|
||||
'min_value', 'max_value'
|
||||
]
|
||||
|
||||
for attr in attrs:
|
||||
value = getattr(field, attr, None)
|
||||
if value is not None and value != '':
|
||||
if value is not None and value != '' and value != empty:
|
||||
field_info[attr] = force_text(value, strings_only=True)
|
||||
|
||||
if getattr(field, 'child', None):
|
||||
|
|
|
@ -69,7 +69,7 @@ class TestMetadata:
|
|||
min_value=1, max_value=1000
|
||||
)
|
||||
char_field = serializers.CharField(
|
||||
required=False, min_length=3, max_length=40
|
||||
required=False, min_length=3, max_length=40, default='Cookie'
|
||||
)
|
||||
list_field = serializers.ListField(
|
||||
child=serializers.ListField(
|
||||
|
@ -128,7 +128,8 @@ class TestMetadata:
|
|||
'read_only': False,
|
||||
'label': 'Char field',
|
||||
'min_length': 3,
|
||||
'max_length': 40
|
||||
'max_length': 40,
|
||||
'default': 'Cookie'
|
||||
},
|
||||
'list_field': {
|
||||
'type': 'list',
|
||||
|
|
Loading…
Reference in New Issue
Block a user