MultiValueDictKeyError at /api/restaurateur/create_meal/ 'data'
Я пытаюсь записать данные в базу данных, но получаю эту ошибку MultiValueDictKeyError at /api/restaurateur/create_meal/ 'data'
Вот мой model.py
class Meal(models.Model):
"""Meal"""
title = models.CharField(max_length=255)
description = models.TextField(default='The description will be later')
price = models.DecimalField(max_digits=9, decimal_places=2)
restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE, null=True)
slug = models.SlugField()
Вот мой views.py
@action(['POST'], detail=False, url_path='create_meal')
def get_restaurant_meals(self, *args, **kwargs):
restaurant = Restaurant.objects.get(owner=self.request.user.restaurateur)
meal_data = self.request.data
meal = Restaurant.objects.create(title=meal_data["data"],
description=meal_data["description"],
price=meal_data["price"],
restaurant=restaurant,
slug=meal_data["slug"],
)
meal.save()
serializer = MealSerializer(meal)
return response.Response(serializer.data, status=status.HTTP_201_CREATED)
Я работаю с django rest framework, мое представление находится в классе viewsets.ModelViewSet