Add 'show_in_bot' field to ProductModel and implement BotProductsView for bot integration

This commit is contained in:
Parsa Nazer
2025-08-04 23:18:30 +03:30
parent d0dfa3eaa7
commit d9b6655ee8
6 changed files with 62 additions and 3 deletions
+31
View File
@@ -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": []
})