Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kszkepzes-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
KSZK
DevTeam
kszkepzes
old
kszkepzes-backend
Commits
97136edc
Commit
97136edc
authored
5 years ago
by
Rafael László
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/download' into dev
parents
7661b095
a00bd376
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Dev
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/document/serializers.py
+19
-7
19 additions, 7 deletions
src/document/serializers.py
with
19 additions
and
7 deletions
src/document/serializers.py
+
19
−
7
View file @
97136edc
...
...
@@ -8,30 +8,42 @@ _max_count = 1
class
DocumentSerializer
(
serializers
.
ModelSerializer
):
uploaded_by
=
serializers
.
HiddenField
(
default
=
CurrentUserProfileDefault
())
uploaded_by_name
=
serializers
.
SerializerMethodField
()
file
=
serializers
.
SerializerMethodField
()
file
_url
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
models
.
Document
fields
=
(
fields
=
[
'
uploaded_by
'
,
'
uploaded_at
'
,
'
name
'
,
'
description
'
,
'
file_url
'
,
'
file
'
,
'
uploaded_by_name
'
,
'
solution
'
,
)
]
read_only_fields
=
[
'
uploaded_by
'
,
'
uploaded_at
'
,
'
file_url
'
,
'
uploaded_by_name
'
,
]
extra_kwargs
=
{
'
file
'
:
{
'
write_only
'
:
True
},
}
def
to_representation
(
self
,
instance
):
data
=
super
().
to_representation
(
instance
)
if
not
data
[
'
file
'
]:
data
[
'
file
'
]
=
""
if
not
data
[
'
file
_url
'
]:
data
[
'
file
_url
'
]
=
""
return
data
def
get_uploaded_by_name
(
self
,
obj
):
return
obj
.
uploaded_by
.
full_name
def
get_file
(
self
,
obj
):
def
get_file
_url
(
self
,
obj
):
return
f
"
/api/v1/documents/
{
obj
.
id
}
/download/
"
def
validate_solution
(
self
,
value
):
...
...
@@ -42,5 +54,5 @@ class DocumentSerializer(serializers.ModelSerializer):
uploaded_by
=
profile
,
solution
=
value
).
count
()
if
count
>=
_max_count
:
raise
serializers
.
ValidationError
(
f
'
You cant upload more than
{
max_count
}
document to one solution!
'
)
f
'
You cant upload more than
{
_
max_count
}
document to one solution!
'
)
return
value
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