Exemplo n.º 1
0
class UpdateSerializer(serializers.HyperlinkedModelSerializer):
    status_verbose = serializers.CharField(source='get_status_display', required=False, read_only=True)
    user = UserPublicSerializer(read_only=True, required=False)

    class Meta:
        model = Update
        fields = ('id', 'description', 'status', 'date', 'status_verbose', 'user')
Exemplo n.º 2
0
class RestaurantProfileSerializer(serializers.ModelSerializer):
    user = UserPublicSerializer(read_only=True)
    category = CategoryProfileSerializer(read_only=True)

    class Meta:
        model = Restaurants
        fields = '__all__'
Exemplo n.º 3
0
class CommentSerializer(serializers.ModelSerializer):
    """model comment serializer"""

    users = UserPublicSerializer()

    class Meta:
        model = Comment
        fields = ("id", "discuss", "campaings", "users", "parentid")
Exemplo n.º 4
0
class BlogPostSerializer(serializers.ModelSerializer):

    user = UserPublicSerializer(read_only = True)

    class Meta:
        model = BlogPost

        fields = [
            "user",
            "title",
            "description",
            "id",
            "post_image",
            "content",
            "timestamp",
            "updated",
            "slug",
            "category"
        ]
Exemplo n.º 5
0
class CHDetailSerializer(serializers.ModelSerializer):
    """campaing header serializer"""

    city = CitySerializer()
    category = CategorySerializer()
    user = UserPublicSerializer()

    class Meta:
        model = CampaingHeader
        fields = (
            "id",
            "user",
            "category",
            "city",
            "qty_day_left",
            "amount",
            "amount_reached",
            "percent_reached",
            "role",
            "code_campaing",
        )
        read_only_fields = ("id", )
Exemplo n.º 6
0
class ReviewSerializer(serializers.ModelSerializer):
    user = UserPublicSerializer(read_only=True)
    comments = CommentSerializer(read_only=True, many=True)

    liked_count = serializers.SerializerMethodField()
    logged_in_user_likes = serializers.SerializerMethodField()

    class Meta:
        model = Reviews
        fields = [
            'id', 'text_content', 'rating', 'date_created', 'date_modified',
            'user', 'likes', 'logged_in_user_likes', 'liked_count', 'comments',
            'restaurant'
        ]

    def get_liked_count(self, obj):
        return obj.likes.count()

    def get_logged_in_user_likes(self, obj):
        if obj.user.id in obj.likes.related_val:
            return True
        else:
            return False
Exemplo n.º 7
0
class CommentSerializer(serializers.ModelSerializer):
    user = UserPublicSerializer(read_only=True)

    class Meta:
        model = Comments
        fields = ['text_content', 'user', 'date_created', 'date_modified', 'likes']