You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.5 KiB

from rest_framework import serializers
from utils import FileFieldSerializer
from .models import Comment, AppVersion
class CommentSerializer(serializers.ModelSerializer):
"""
Serializer for Comment model with proper file field serialization for avatar
"""
user_avatar = FileFieldSerializer(required=False, allow_null=True)
class Meta:
model = Comment
fields = [
'id',
'user_avatar',
'user_fullname',
'user_slogan',
'comment_text',
'order',
'created_at'
]
read_only_fields = ['id', 'created_at']
def validate_user_fullname(self, value):
if not value or not value.strip():
raise serializers.ValidationError("User full name is required.")
return value
def validate_comment_text(self, value):
if not value or not value.strip():
raise serializers.ValidationError("Comment text is required.")
return value
class AppVersionSerializer(serializers.ModelSerializer):
apk_file = FileFieldSerializer()
class Meta:
model = AppVersion
fields = [
'id',
'version',
'apk_file',
'description',
'app_type',
'app_store_downloads',
'google_play_downloads',
'is_active',
'created_at',
'updated_at',
]
read_only_fields = ['id', 'created_at', 'updated_at']