models.py
class Product(models.Model):
product_name = models.CharField(max_length=32)
quantity = models.IntegerField()
remarks = models.TextField(blank=True)
class Vendor(models.Model):
vendor_name = models.CharField(max_length=50)
address = models.CharField(max_length=100)
bill_no = models.CharField(max_length=8)
product = models.ManyToManyField(Product)
serializers.py
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = '__all__'
class VendorSerializer(serializers.ModelSerializer):
product = ProductSerializer(many=True, read_only=False)
class Meta:
model = Vendor
fields = '__all__'
views.py
from rest_framework import viewsets
class VendorViewset(viewsets.ModelViewSet):
serializer_class = VendorSerializer
queryset = Vendor.objects.all()
Как переопределить доступный для записи метод create () в VendorSerializerдобавить информацию о товарах продавцам, которые относятся к поставщику?