Here are my model relationships:
|---Retailer
|---Product
|---Coupon
Now I have a view that returns me each retailer with its products:
class ProductList(APIView):
def get(self, request):
retailer = Retailer.objects.all()
serializer = RetailerSerializer(retailer, many=True)
data = serializer.data
return JsonResponse({'data': data}, safe=False)
And here's RetailerSerializer:
class RetailerSerializer(serializers.ModelSerializer):
products = ProductSerializer(many=True, read_only=True)
class Meta:
model = Retailer
fields = ['name', 'website','description', 'products']
depth = 1
Now I want to get count coupons in each product. What should i do?