Files
vontor-cz/backend/social/posts/serializers.py
2026-04-20 00:04:15 +02:00

32 lines
1.1 KiB
Python

from rest_framework import serializers
from .models import Post, PostContent, PostVote
from social.hubs.serializers import TagsSerializer
class PostContentSerializer(serializers.ModelSerializer):
class Meta:
model = PostContent
fields = ['id', 'mime_type', 'file', 'alt_text']
read_only_fields = ['mime_type']
class PostSerializer(serializers.ModelSerializer):
contents = PostContentSerializer(many=True, read_only=True)
tags = TagsSerializer(many=True, read_only=True)
class Meta:
model = Post
fields = ['id', 'content', 'created_at', 'updated_at', 'author', 'hub', 'reply_to', 'tags', 'contents']
read_only_fields = ['author', 'created_at', 'updated_at']
class PostVoteSerializer(serializers.ModelSerializer):
class Meta:
model = PostVote
fields = ['id', 'post', 'user', 'vote', 'created_at']
read_only_fields = ['user', 'created_at']
class TagAttachSerializer(serializers.Serializer):
tag_id = serializers.IntegerField(help_text="PK of the hub tag to attach or detach.")