I have model Product:
def productFile(instance, filename):
return '/'.join( ['products', str(instance.id), filename] )
class Product(models.Model):
...
image = models.ImageField(
upload_to=productFile,
max_length=254, blank=True, null=True
)
...
Then I have serializer:
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = (
...
'image',
...
)
And then I have views:
class ProductViewSet(BaseViewSet, viewsets.ModelViewSet):
queryset = Product.objects.all()
serializer_class = ProductSerializer
How I can upload image with Postman? What is the best practices to upload image to model? Thank you.