Example #1
0
class MediaListSerializer(serializers.ModelSerializer):
    creator = UserSerializer()
    image = ImageSerializer()

    class Meta:
        model = Media
        fields = ("pk", "title", "image", "likes", "views", "creator", "status", "is_ban")
Example #2
0
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",
        )
Example #3
0
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",
        )
Example #4
0
class NewsListSerializer(serializers.ModelSerializer):
    image = ImageSerializer()
    creator = UserSerializer()

    class Meta:
        model = News
        fields = ("pk", "title", "image", "creator", "description",
                  "publish_date", "end_publish_date")
Example #5
0
class CommentItemSerializer(serializers.ModelSerializer):
    creator = UserSerializer()
    children = RecursiveField(many=True)

    class Meta:
        model = Comment
        fields = ("pk", "parent", "comment", "likes", "creator",
                  "created_date", "children")
Example #6
0
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")
Example #7
0
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",
        )
Example #8
0
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")
Example #9
0
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",
        )
Example #10
0
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",
        )
Example #11
0
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",
        )
Example #12
0
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",
        )
Example #13
0
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",
        )
Example #14
0
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",
        )
Example #15
0
class BlackListItemSerializer(serializers.ModelSerializer):
    user = UserSerializer()

    class Meta:
        model = BlackList
        fields = ("pk", "user", "reason", "reason_message")
Example #16
0
 def get_moderators(self, obj):
     serializer = UserSerializer(obj.get_chat_moderators(),
                                 many=True,
                                 context=self.context)
     return serializer.data
Example #17
0
class ClubPartySerializer(serializers.ModelSerializer):
    moderators = UserSerializer(many=True)

    class Meta:
        model = Club
        fields = ("pk", "slug", "name", "moderators")