mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Limit blank string -> None to just be on relational fields
This commit is contained in:
parent
5ead8dc89d
commit
f7d43f530a
|
@ -110,7 +110,6 @@ class Field(object):
|
|||
default_validators = []
|
||||
default_empty_html = empty
|
||||
initial = None
|
||||
coerce_blank_to_null = True
|
||||
|
||||
def __init__(self, read_only=False, write_only=False,
|
||||
required=None, default=empty, initial=empty, source=None,
|
||||
|
@ -248,9 +247,6 @@ class Field(object):
|
|||
self.fail('required')
|
||||
return self.get_default()
|
||||
|
||||
if data == '' and self.coerce_blank_to_null:
|
||||
data = None
|
||||
|
||||
if data is None:
|
||||
if not self.allow_null:
|
||||
self.fail('null')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from rest_framework.compat import smart_text, urlparse
|
||||
from rest_framework.fields import Field
|
||||
from rest_framework.fields import empty, Field
|
||||
from rest_framework.reverse import reverse
|
||||
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
|
||||
from django.core.urlresolvers import resolve, get_script_prefix, NoReverseMatch, Resolver404
|
||||
|
@ -31,6 +31,12 @@ class RelatedField(Field):
|
|||
)
|
||||
return super(RelatedField, cls).__new__(cls, *args, **kwargs)
|
||||
|
||||
def run_validation(self, data=empty):
|
||||
# We force empty strings to None values for relational fields.
|
||||
if data == '':
|
||||
data = None
|
||||
return super(RelatedField, self).run_validation(data)
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = self.queryset
|
||||
if isinstance(queryset, QuerySet):
|
||||
|
|
Loading…
Reference in New Issue
Block a user