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
5408fe00
Commit
5408fe00
authored
2 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Fix HostSerializer, add missing fields & read-only fields
- `HostLinkSerializer` is a `serializers.ModelSerializer` again.
parent
c06dbb61
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/serializers.py
+12
-3
12 additions, 3 deletions
program/serializers.py
with
12 additions
and
3 deletions
program/serializers.py
+
12
−
3
View file @
5408fe00
...
...
@@ -167,9 +167,10 @@ class LinkSerializer(serializers.ModelSerializer):
fields
=
(
"
description
"
,
"
url
"
)
class
HostLinkSerializer
(
Link
Serializer
):
class
HostLinkSerializer
(
serializers
.
Model
Serializer
):
class
Meta
:
model
=
HostLink
fields
=
(
"
description
"
,
"
url
"
)
class
HostSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -194,6 +195,8 @@ class HostSerializer(serializers.ModelSerializer):
"
email
"
,
"
biography
"
,
"
is_active
"
,
"
links
"
,
"
thumbnails
"
,
# ModelWithImageFields
"
image
"
,
"
image_ppoi
"
,
...
...
@@ -207,11 +210,16 @@ class HostSerializer(serializers.ModelSerializer):
"
updated_at
"
,
"
updated_by
"
,
)
read_only_fields
=
(
"
created_at
"
,
"
created_by
"
,
"
updated_at
"
,
"
updated_by
"
,
)
def
create
(
self
,
validated_data
):
links_data
=
validated_data
.
pop
(
"
links
"
,
[])
host
=
Host
.
objects
.
create
(
**
validated_data
)
host
=
Host
.
objects
.
create
(
**
validated_data
|
self
.
context
)
for
link_data
in
links_data
:
HostLink
.
objects
.
create
(
host
=
host
,
**
link_data
)
host
.
save
()
...
...
@@ -234,6 +242,7 @@ class HostSerializer(serializers.ModelSerializer):
instance
.
image_alt_text
=
validated_data
.
get
(
"
image_alt_text
"
,
instance
.
image_alt_text
)
instance
.
updated_by
=
self
.
context
.
get
(
"
updated_by
"
)
if
instance
.
links
.
count
()
>
0
:
for
link
in
instance
.
links
.
all
():
...
...
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