Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
566e90f9
Verified
Commit
566e90f9
authored
Sep 11, 2017
by
Thibaut Broggi
Browse files
Add tags in article API responses
parent
04bcd303
Pipeline
#1205
passed with stages
in 1 minute and 57 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/api/serializers.py
View file @
566e90f9
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
taggit.managers
import
TaggableManager
from
rp.models
import
Article
from
rp.models
import
Article
class
TagListSerializer
(
serializers
.
Field
):
class
Meta
:
model
=
TaggableManager
(
blank
=
True
)
def
to_representation
(
self
,
obj
):
if
type
(
obj
)
is
not
list
:
return
[
tag
.
name
for
tag
in
obj
.
all
()]
return
obj
class
ArticleSerializer
(
serializers
.
ModelSerializer
):
class
ArticleSerializer
(
serializers
.
ModelSerializer
):
tags
=
TagListSerializer
()
class
Meta
:
class
Meta
:
model
=
Article
model
=
Article
fields
=
(
'id'
,
'url'
,
'title'
,
'extracts'
,
'und_score_up'
,
'und_score_down'
)
fields
=
(
'id'
,
'url'
,
'title'
,
'tags'
,
'extracts'
,
'und_score_up'
,
'und_score_down'
)
Write
Preview
Supports
Markdown
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