mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-22 09:46: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 self.context["request"].user.is_authenticated:
|
if "request" in self.context:
|
||||||
return SongUserRating.objects.filter(
|
if self.context["request"].user.is_authenticated:
|
||||||
song=obj, user=self.context["request"].user, like=True
|
return SongUserRating.objects.filter(
|
||||||
).exists()
|
song=obj, user=self.context["request"].user, like=True
|
||||||
|
).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"]
|
||||||
return obj.id in self.context["likes_ids"]
|
if "likes_ids" in self.context:
|
||||||
|
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