Skip to content
Snippets Groups Projects
Commit 97136edc authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

Merge remote-tracking branch 'origin/download' into dev

parents 7661b095 a00bd376
No related branches found
No related tags found
1 merge request!2Dev
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment