I've found many answers to similar questions but not to my specific one. I'm trying to update the Create Method for my serializer which has two nested serializers:
class TaskSerializer(serializers.ModelSerializer):
products = ProductSerializer()
prep = PrepSerializer()
class Meta:
model = Task
fields = '__all__'
def create(self, validated_data):
products_data = validated_data.pop('products')
task = Task.objects.create(**validated_data)
for products_data in products_data:
Product.objects.create(task=task, **products_data)
return task
I want to add the "prep" nested serializer in as well to be updated at the same time but I can't seem get the syntax right.
Any help, greatly appreciated.