Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
6e622d64
Commit
6e622d64
authored
Jan 05, 2014
by
Yuri Prezument
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CharField - add allow_null argument
parent
e88e3c6a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
docs/api-guide/fields.md
+4
-3
rest_framework/fields.py
+3
-2
No files found.
docs/api-guide/fields.md
View file @
6e622d64
...
...
@@ -157,23 +157,24 @@ Corresponds to `django.db.models.fields.BooleanField`.
## CharField
A text representation, optionally validates the text to be shorter than `max_length` and longer than `min_length`.
If `allow_none` is `False` (default), `None` values will be converted to an empty string.
Corresponds to `django.db.models.fields.CharField`
or `django.db.models.fields.TextField`.
*
*Signature
:** `CharField(max_length=None, min_length=None)`
*
*Signature
:** `CharField(max_length=None, min_length=None
, allow_none=False
)`
## URLField
Corresponds to `django.db.models.fields.URLField`. Uses Django's `django.core.validators.URLValidator` for validation.
*
*Signature
:** `CharField(max_length=200, min_length=None)`
*
*Signature
:** `CharField(max_length=200, min_length=None
, allow_none=False
)`
## SlugField
Corresponds to `django.db.models.fields.SlugField`.
*
*Signature
:** `CharField(max_length=50, min_length=None)`
*
*Signature
:** `CharField(max_length=50, min_length=None
, allow_none=False
)`
## ChoiceField
...
...
rest_framework/fields.py
View file @
6e622d64
...
...
@@ -443,8 +443,9 @@ class CharField(WritableField):
type_label
=
'string'
form_field_class
=
forms
.
CharField
def
__init__
(
self
,
max_length
=
None
,
min_length
=
None
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
max_length
=
None
,
min_length
=
None
,
allow_none
=
False
,
*
args
,
**
kwargs
):
self
.
max_length
,
self
.
min_length
=
max_length
,
min_length
self
.
allow_none
=
allow_none
super
(
CharField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
if
min_length
is
not
None
:
self
.
validators
.
append
(
validators
.
MinLengthValidator
(
min_length
))
...
...
@@ -452,7 +453,7 @@ class CharField(WritableField):
self
.
validators
.
append
(
validators
.
MaxLengthValidator
(
max_length
))
def
from_native
(
self
,
value
):
if
value
is
None
:
if
value
is
None
and
not
self
.
allow_none
:
return
''
if
isinstance
(
value
,
six
.
string_types
):
return
value
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment