Ошибка "image_file": [ "Обязательное поле."]
у меня есть serializer
class ImageFileSerializer(serializers.ModelSerializer):
class Meta:
model = ImageFile
fields = ["image"]
class DescriptionFileSerializer(serializers.ModelSerializer):
image_file = ImageFileSerializer(many=True)
file_filename = serializers.CharField()
tags = serializers.SlugRelatedField(many=True, slug_field='name',
queryset=Tags.objects.all())
class Meta:
model = DescriptionFile
fields = ['file_filename', 'user', 'title', 'description', 'line_video', 'tags',
'image_file', "time_create"]
read_only_fields = ('time_create',)
я сделал небольшую html форму на отправку запроса на это views:
class DescriptionFileView(ModelViewSet):
queryset = DescriptionFile.objects.all().annotate(
file_filename=F("file__filename")
).select_related("user", 'file').prefetch_related("tags", "image_file")
serializer_class = DescriptionFileSerializer
filter_backends = [SearchFilter]
search_fields = ["time_create", "user__id", "tags__name"]
def get(self, request, *args, **kwargs):
csrf_token = get_token(request)
return Response({'csrf_token': csrf_token})
def post(self, request, *args, **kwargs):
csrf_token = get_token(request)
if csrf_token is None:
return Response({'error': 'CSRF token missing'}, status=403)
return self.create(request, *args, **kwargs)
добавив само фото, мне приходит в ответ:
{
"image_file": [
"Обязательное поле."
]
}
что мне делать?
python == 3.11.9
django == 4.2.11
drf == 3.15.1