Add 'show_in_bot' field to ProductModel and implement BotProductsView for bot integration
This commit is contained in:
@@ -429,3 +429,34 @@ class CommentView(APIView):
|
||||
return Response({"detail": "شما اجازه ی پاک کردن این کامنت را ندارید"}, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import serializers
|
||||
from .models import ProductModel
|
||||
|
||||
class BotProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductModel
|
||||
fields = ['pk', 'name']
|
||||
|
||||
class BotProductsView(APIView):
|
||||
serializer_class = BotProductSerializer
|
||||
|
||||
def get(self, request):
|
||||
bot_products = ProductModel.objects.filter(show_in_bot=True)
|
||||
|
||||
if bot_products.exists():
|
||||
serialized = self.serializer_class(bot_products, many=True)
|
||||
return Response({
|
||||
"success": True,
|
||||
"products": serialized.data
|
||||
})
|
||||
else:
|
||||
return Response({
|
||||
"success": False,
|
||||
"products": []
|
||||
})
|
||||
Reference in New Issue
Block a user