gukgjzkgjhgjh
This commit is contained in:
31
backend/social/posts/serializers.py
Normal file
31
backend/social/posts/serializers.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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.")
|
||||
Reference in New Issue
Block a user