Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
gm-serializer
Project
Project
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
backend
gm-serializer
Commits
8bf30ec9
Commit
8bf30ec9
authored
Jul 05, 2017
by
gushitong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update README.md
parent
e4025d59
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
6 deletions
+25
-6
README.md
README.md
+25
-6
No files found.
README.md
View file @
8bf30ec9
...
...
@@ -27,12 +27,12 @@ class Question(models.Model):
class
QuestionSerializer
(
serializers
.
GmModelSerializer
):
user
=
serializers
.
WeakRelField
(
validators
=
[
serializers
.
BlacklistValidator
]
)
content
=
serializers
.
TextField
(
validators
=
[
serializers
.
FilterWordValidator
]
)
user
=
serializers
.
WeakRelField
(
validators
=
[
serializers
.
BlacklistValidator
]
)
content
=
serializers
.
TextField
(
validators
=
[
serializers
.
FilterWordValidator
]
)
class
Meta
:
model
=
Question
...
...
@@ -40,3 +40,22 @@ class QuestionSerializer(serializers.GmModelSerializer):
fields
=
'__all__'
```
```
python
>>>
from
answer.models
import
Question
>>>
from
answer.serializers.question
import
QuestionSerializer
>>>
q
=
Question
.
objects
.
first
()
>>>
q
.
user
{
u'city_id'
:
None
,
u'user_rights_level'
:
u'1'
,
u'topic_count'
:
0
,
u'city_name'
:
None
,
u'portrait'
:
u'http://pic.gmei.com/user/icon7@2x.png-thumb'
,
u'country_tag_id'
:
None
,
u'nickname'
:
u'18*******4*'
,
u'id'
:
2500
,
u'membership_level'
:
u'0'
,
u'level_icon'
:
u'http://hera.s.gmei.com/2017/06/12/d2068222ba'
,
u'constellation'
:
u''
,
u'membership_icon'
:
u''
,
u'vote_count'
:
u'0'
,
u'city_tag_id'
:
None
,
u'constellation_icon'
:
u''
,
u'person_id'
:
u'55729f2e5aa111e5a2a200163e00488a'
,
u'province_tag_id'
:
None
}
>>>
qs
=
Question
.
objects
.
all
()[:
2
]
>>>
>>>
QuestionSerializer
(
qs
,
many
=
True
)
.
data
[
OrderedDict
([(
u'id'
,
1
),
(
'user'
,
u"{u'city_id': None, u'user_rights_level': u'1', u'topic_count': u'0', u'city_name': None, u'portrait': u'http://pic.gmei.com/user/icon7@2x.png-thumb', u'country_tag_id': None, u'nickname': u'18*******4*', u'id': 2500, u'membership_level': u'0', u'level_icon': u'http://hera.s.gmei.com/2017/06/12/d2068222ba', u'constellation': u'', u'membership_icon': u'', u'vote_count': u'0', u'city_tag_id': None, u'constellation_icon': u'', u'person_id': u'55729f2e5aa111e5a2a200163e00488a', u'province_tag_id': None}"
),
(
'title'
,
u'auto question title'
),
(
'content'
,
u'auto question XuraDFEiam'
),
(
'cover_url'
,
None
),
(
'is_online'
,
True
),
(
'is_recommend'
,
False
),
(
'like_num'
,
0
),
(
'create_time'
,
'2017-06-27T17:55:41.404296'
),
(
'update_time'
,
'2017-07-04T16:55:59.389776'
),
(
'is_spam'
,
False
),
(
'problem_id'
,
None
),
(
'city_id'
,
None
)]),
OrderedDict
([(
u'id'
,
2
),
(
'user'
,
u"{u'city_id': u'beijing', u'user_rights_level': u'1', u'topic_count': 0, u'city_name': u'
\\
u5317
\\
u4eac', u'portrait': u'http://pic.gmei.com/userextra/2016/09/08/165c678aa2-thumb', u'country_tag_id': 259, u'nickname': u'xxxxxxx', u'id': 1, u'membership_level': u'1', u'level_icon': u'', u'constellation': u'', u'membership_icon': u'', u'vote_count': u'0', u'city_tag_id': 328, u'constellation_icon': u'', u'person_id': u'e03b55b85a9911e5a2a200163e00488a', u'province_tag_id': 264}"
),
(
'title'
,
u'auto question title'
),
(
'content'
,
u'auto question XuraDFEiam'
),
(
'cover_url'
,
None
),
(
'is_online'
,
True
),
(
'is_recommend'
,
False
),
(
'like_num'
,
0
),
(
'create_time'
,
'2017-06-27T17:55:41.404296'
),
(
'update_time'
,
'2017-06-27T17:55:41.423131'
),
(
'is_spam'
,
False
),
(
'problem_id'
,
None
),
(
'city_id'
,
None
)])]
>>>
QuestionSerializer
(
qs
,
many
=
True
,
lazy
=
True
)
.
data
[
OrderedDict
([(
u'id'
,
1
),
(
'user'
,
2500L
),
(
'title'
,
u'auto question title'
),
(
'content'
,
u'auto question XuraDFEiam'
),
(
'cover_url'
,
None
),
(
'is_online'
,
True
),
(
'is_recommend'
,
False
),
(
'like_num'
,
0
),
(
'create_time'
,
'2017-06-27T17:55:41.404296'
),
(
'update_time'
,
'2017-07-04T16:55:59.389776'
),
(
'is_spam'
,
False
),
(
'problem_id'
,
None
),
(
'city_id'
,
None
)]),
OrderedDict
([(
u'id'
,
2
),
(
'user'
,
1L
),
(
'title'
,
u'auto question title'
),
(
'content'
,
u'auto question XuraDFEiam'
),
(
'cover_url'
,
None
),
(
'is_online'
,
True
),
(
'is_recommend'
,
False
),
(
'like_num'
,
0
),
(
'create_time'
,
'2017-06-27T17:55:41.404296'
),
(
'update_time'
,
'2017-06-27T17:55:41.423131'
),
(
'is_spam'
,
False
),
(
'problem_id'
,
None
),
(
'city_id'
,
None
)])]
>>>
>>>
serializer
=
QuestionSerializer
(
data
=
{
"user"
:
1000
,
"title"
:
"title"
,
"content"
:
"content"
})
>>>
serializer
.
is_valid
()
True
>>>
serializer
.
save
()
```
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