Django CreateAPIView not saving image portion of django model

150 views Asked by At

I am trying to make a django rest api which allows admin users to add images which the api clients can sync and display. My view responsible for creating the Clothing model, which holds a title and an image, is not working as it only saves the title but not the image.

Here is the Clothing model:

class Clothing(models.Model):
    title = models.CharField(max_length=50, blank=False)
    img = models.ImageField(blank=True, null=True, upload_to='catalog/')

Here is the view:

class AddClothingView(CreateAPIView):
    queryset = Clothing.objects.all()
    serializer_class = ClothingSerializer

And here is the serializer:

class ClothingSerializer(ModelSerializer):
    class Meta:
        model = Clothing
        fields = '__all__'

How can I fix this such that the images are saved in the catalog/ folder in my project?

0

There are 0 answers