mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-22 14:26:34 +03:00
updated serializer
This commit is contained in:
parent
debdf53927
commit
63311d1d26
|
@ -32,10 +32,12 @@ class SongSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
@extend_schema_field(serializers.BooleanField)
|
@extend_schema_field(serializers.BooleanField)
|
||||||
def get_liked(self, obj):
|
def get_liked(self, obj):
|
||||||
|
if "request" in self.context:
|
||||||
if self.context["request"].user.is_authenticated:
|
if self.context["request"].user.is_authenticated:
|
||||||
return SongUserRating.objects.filter(
|
return SongUserRating.objects.filter(
|
||||||
song=obj, user=self.context["request"].user, like=True
|
song=obj, user=self.context["request"].user, like=True
|
||||||
).exists()
|
).exists()
|
||||||
|
return None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Song
|
model = Song
|
||||||
|
@ -66,7 +68,9 @@ class ListSongSerializer(SetUserModelSerializer):
|
||||||
def get_liked(self, obj):
|
def get_liked(self, obj):
|
||||||
if "likes" in self.context:
|
if "likes" in self.context:
|
||||||
return self.context["likes"]
|
return self.context["likes"]
|
||||||
|
if "likes_ids" in self.context:
|
||||||
return obj.id in self.context["likes_ids"]
|
return obj.id in self.context["likes_ids"]
|
||||||
|
return None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Song
|
model = Song
|
||||||
|
|
Loading…
Reference in New Issue
Block a user