Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
cfdceeed
Commit
cfdceeed
authored
3 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Add LinkSerializer and modify HostSerializer to handle nested links
parent
dc0c6722
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/serializers.py
+24
-1
24 additions, 1 deletion
program/serializers.py
with
24 additions
and
1 deletion
program/serializers.py
+
24
−
1
View file @
cfdceeed
...
...
@@ -26,7 +26,7 @@ from rest_framework import serializers
from
profile.models
import
Profile
from
profile.serializers
import
ProfileSerializer
from
program.models
import
Show
,
Schedule
,
TimeSlot
,
Category
,
FundingCategory
,
Host
,
Topic
,
MusicFocus
,
Note
,
Type
,
Language
,
\
RRule
RRule
,
Link
from
steering.settings
import
THUMBNAIL_SIZES
...
...
@@ -111,7 +111,14 @@ class CategorySerializer(serializers.ModelSerializer):
return
instance
class
LinkSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Link
fields
=
(
'
description
'
,
'
url
'
)
class
HostSerializer
(
serializers
.
ModelSerializer
):
links
=
LinkSerializer
(
many
=
True
)
thumbnails
=
serializers
.
SerializerMethodField
()
# Read-only
@staticmethod
...
...
@@ -129,6 +136,15 @@ class HostSerializer(serializers.ModelSerializer):
model
=
Host
fields
=
'
__all__
'
def
create
(
self
,
validated_data
):
links_data
=
validated_data
.
pop
(
'
links
'
)
host
=
Host
.
objects
.
create
(
**
validated_data
)
for
link_data
in
links_data
:
Link
.
objects
.
create
(
host
=
host
,
**
link_data
)
host
.
save
()
return
host
def
update
(
self
,
instance
,
validated_data
):
"""
Update and return an existing Host instance, given the validated data.
...
...
@@ -142,7 +158,14 @@ class HostSerializer(serializers.ModelSerializer):
instance
.
image
=
validated_data
.
get
(
'
image
'
,
instance
.
image
)
instance
.
ppoi
=
validated_data
.
get
(
'
ppoi
'
,
instance
.
ppoi
)
for
link
in
instance
.
links
.
all
():
link
.
delete
(
keep_parents
=
True
)
for
link_data
in
validated_data
.
get
(
'
links
'
):
Link
.
objects
.
create
(
host
=
instance
,
**
link_data
)
instance
.
save
()
return
instance
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment