class RecipeSerializer(serializers.ModelSerializer):
    ingredients = IngredientSerializer(many=True)


class Meta:
    model = Recipe

def create(self, validated_data):
    ingredients_data = validated_data.pop('ingredients')
recipe = Recipe.objects.create(**validated_data)
for ingredient in ingredients_data:
    ingredient, created = Ingredient.objects.get_or_create(name=ingredient[
        'name'])
recipe.ingredients.add(ingredient)
Вложенные сериализаторы Django Rest Framework с возможностью записи