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
86484668
Commit
86484668
authored
Nov 20, 2012
by
Stephan Groß
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added RegexField
parent
44e9749e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
0 deletions
+40
-0
docs/api-guide/fields.md
+10
-0
docs/topics/release-notes.md
+1
-0
rest_framework/fields.py
+29
-0
No files found.
docs/api-guide/fields.md
View file @
86484668
...
@@ -141,6 +141,16 @@ A text representation, validates the text to be a valid e-mail address.
...
@@ -141,6 +141,16 @@ A text representation, validates the text to be a valid e-mail address.
Corresponds to
`django.db.models.fields.EmailField`
Corresponds to
`django.db.models.fields.EmailField`
## RegexField
A text representation, that validates the given value matches against a certain regular expression.
Uses Django's
`django.core.validators.RegexValidator`
for validation.
Corresponds to
`django.forms.fields.RegexField`
**Signature:**
`RegexField(regex, max_length=None, min_length=None)`
## DateField
## DateField
A date representation.
A date representation.
...
...
docs/topics/release-notes.md
View file @
86484668
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
## Master
## Master
*
Support for
`read_only_fields`
on
`ModelSerializer`
classes.
*
Support for
`read_only_fields`
on
`ModelSerializer`
classes.
*
Added
`RegexField`
.
## 2.1.2
## 2.1.2
...
...
rest_framework/fields.py
View file @
86484668
import
copy
import
copy
import
datetime
import
datetime
import
inspect
import
inspect
import
re
import
warnings
import
warnings
from
django.core
import
validators
from
django.core
import
validators
...
@@ -768,6 +769,34 @@ class EmailField(CharField):
...
@@ -768,6 +769,34 @@ class EmailField(CharField):
return
result
return
result
class
RegexField
(
CharField
):
type_name
=
'RegexField'
def
__init__
(
self
,
regex
,
max_length
=
None
,
min_length
=
None
,
*
args
,
**
kwargs
):
super
(
RegexField
,
self
)
.
__init__
(
max_length
,
min_length
,
*
args
,
**
kwargs
)
self
.
regex
=
regex
def
_get_regex
(
self
):
return
self
.
_regex
def
_set_regex
(
self
,
regex
):
if
isinstance
(
regex
,
basestring
):
regex
=
re
.
compile
(
regex
)
self
.
_regex
=
regex
if
hasattr
(
self
,
'_regex_validator'
)
and
self
.
_regex_validator
in
self
.
validators
:
self
.
validators
.
remove
(
self
.
_regex_validator
)
self
.
_regex_validator
=
validators
.
RegexValidator
(
regex
=
regex
)
self
.
validators
.
append
(
self
.
_regex_validator
)
regex
=
property
(
_get_regex
,
_set_regex
)
def
__deepcopy__
(
self
,
memo
):
result
=
copy
.
copy
(
self
)
memo
[
id
(
self
)]
=
result
result
.
validators
=
self
.
validators
[:]
return
result
class
DateField
(
WritableField
):
class
DateField
(
WritableField
):
type_name
=
'DateField'
type_name
=
'DateField'
...
...
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