class MediaListSerializer(serializers.ModelSerializer): creator = UserSerializer() image = ImageSerializer() class Meta: model = Media fields = ("pk", "title", "image", "likes", "views", "creator", "status", "is_ban")
class MediaSerializer(serializers.ModelSerializer): image = ImageSerializer() creator = UserSerializer() content_type = ContentTypeField() title = serializers.SerializerMethodField() def get_title(self, obj): return obj.get_title() class Meta: model = Media fields = ( "pk", "title", "description", "image", "video_code", "media_type", "hash_tags", "views", "likes", "comments_count", "creator", "status", "object_id", "content_type", )
class UserListSerializer(serializers.ModelSerializer): city = CitySerializer() role = ChoiceDisplayField(choices=User.ROLES) approver = UserSerializer() avatar = ImageSerializer() role = ChoiceDisplayField(choices=User.ROLES) gender = ChoiceDisplayField(choices=User.GENDERS) relationship_formats = ChoiceDisplayField(choices=User.FORMATS) relationship_themes = ChoiceDisplayField(choices=ThemeChoices.THEMES) class Meta: model = User fields = ( "pk", "slug", "name", "avatar", "email", "is_real", "approver", "role", "about", "is_ban", "gender", "relationship_formats", "relationship_themes", "birthday", "birthday_second", "city", )
class NewsListSerializer(serializers.ModelSerializer): image = ImageSerializer() creator = UserSerializer() class Meta: model = News fields = ("pk", "title", "image", "creator", "description", "publish_date", "end_publish_date")
class CommentItemSerializer(serializers.ModelSerializer): creator = UserSerializer() children = RecursiveField(many=True) class Meta: model = Comment fields = ("pk", "parent", "comment", "likes", "creator", "created_date", "children")
class ClubListSerializer(serializers.ModelSerializer): creator = UserSerializer() image = ImageSerializer() city = CitySerializer() class Meta: model = Club fields = ("pk", "slug", "image", "name", "description", "city", "creator", "status", "is_ban")
class GroupRetrieveSerializer(GroupListSerializer): moderators = UserSerializer(many=True) users = UserSerializer(many=True) class Meta: model = Group fields = ( "pk", "slug", "name", "image", "description", "relationship_theme", "group_type", "creator", "moderators", "users", "requests_count", "request", )
class MessageListSerializer(serializers.ModelSerializer): creator = UserSerializer(read_only=True) attachments_data = serializers.SerializerMethodField() def get_attachments_data(self, obj): serializer = ImageSerializer(obj.attachments.all(), many=True, context=self.context) return serializer.data class Meta: model = Message fields = ("pk", "message", "creator", "attachments_data", "created_date")
class ClubRetrieveSerializer(ClubListSerializer): moderators = UserSerializer(many=True) users = UserSerializer(many=True) class Meta: model = Club fields = ( "pk", "slug", "name", "image", "description", "relationship_theme", "club_type", "city", "address", "geo", "status", "creator", "moderators", "users", "requests_count", "request", )
class NewsItemSerializer(serializers.ModelSerializer): image = ImageSerializer() creator = UserSerializer() news_type = ChoiceDisplayField(choices=News.TYPES) likes = serializers.SerializerMethodField() views = serializers.SerializerMethodField() comments_count = serializers.SerializerMethodField() def get_likes(self, obj): parent = obj.content_object if parent and hasattr(parent, "likes"): return parent.likes.all().values_list("pk", flat=True) return obj.likes.all().values_list("pk", flat=True) def get_views(self, obj): parent = obj.content_object if parent and hasattr(parent, "views"): return parent.views return obj.views def get_comments_count(self, obj): parent = obj.content_object if parent and hasattr(parent, "comments_count"): return parent.comments_count return obj.comments_count class Meta: model = News fields = ( "pk", "news_type", "slug", "object_id", "title", "image", "creator", "description", "publish_date", "views", "likes", "comments_count", "hash_tags", )
class PostListSerializer(serializers.ModelSerializer): creator = UserSerializer() theme = ChoiceDisplayField(choices=Post.THEMES) image = ImageSerializer() class Meta: model = Post fields = ( "pk", "slug", "image", "title", "description", "theme", "likes", "views", "creator", "status", "is_ban", )
class MediaItemSerializer(serializers.ModelSerializer): image = ImageSerializer() creator = UserSerializer() class Meta: model = Media fields = ( "pk", "title", "description", "image", "video_code", "media_type", "hash_tags", "views", "likes", "comments_count", "creator", "status", )
class PostSerializer(serializers.ModelSerializer): image = ImageSerializer() creator = UserSerializer() class Meta: model = Post fields = ( "pk", "slug", "title", "image", "description", "post", "views", "likes", "comments_count", "hash_tags", "creator", "status", "theme", "is_whisper", )
class NewsSerializer(serializers.ModelSerializer): image = ImageSerializer() creator = UserSerializer() news_type = ChoiceDisplayField(choices=News.TYPES) class Meta: model = News fields = ( "pk", "news_type", "slug", "object_id", "title", "image", "creator", "description", "news", "publish_date", "views", "likes", "comments_count", "hash_tags", )
class BlackListItemSerializer(serializers.ModelSerializer): user = UserSerializer() class Meta: model = BlackList fields = ("pk", "user", "reason", "reason_message")
def get_moderators(self, obj): serializer = UserSerializer(obj.get_chat_moderators(), many=True, context=self.context) return serializer.data
class ClubPartySerializer(serializers.ModelSerializer): moderators = UserSerializer(many=True) class Meta: model = Club fields = ("pk", "slug", "name", "moderators")