Skip to content

Commit

Permalink
update some actions
Browse files Browse the repository at this point in the history
  • Loading branch information
khasanjon-dev committed Nov 23, 2023
1 parent 86a7c37 commit 246fcae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions apps/products/serializers/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from rest_framework.serializers import ModelSerializer

from products.models import Product
from users.models import Favorite


class ProductModelSerializer(ModelSerializer):
Expand All @@ -24,5 +23,5 @@ def to_representation(self, instance):
rep = super().to_representation(instance)
request = self.context['request']
if request.user.is_authenticated:
rep['is_like'] = Favorite.objects.filter(customer=request.user, is_like=True).exists()
rep['is_like'] = instance.favorites.filter(is_like=True, customer=request.user).exists()
return rep
5 changes: 3 additions & 2 deletions apps/products/views/product.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from products.models import Product
from products.serializers.product import ProductModelSerializer
from rest_framework.mixins import ListModelMixin
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.viewsets import GenericViewSet

from products.models import Product
from products.serializers.product import ProductModelSerializer


class ProductViewSet(ListModelMixin, GenericViewSet):
"""
Expand Down

0 comments on commit 246fcae

Please sign in to comment.