I am working with an application using the Django Rest Framework.
models.py
class Image(models.Model): image_meta = models.ForeignKey('Image_Meta',on_delete=models.CASCADE,) image_path = models.URLField(max_length=200) order = models.IntegerField() version = models.CharField(max_length=10)
serializers.py
class ImageSerializer(serializers.ModelSerializer): class Meta: model = Image field = ('id', 'image_path' , 'order' , 'version')
views.py
class ImageList(generics.ListCreateAPIView): queryset = Image.objects.all() serializer_class = ImageSerializer class ImageDetail(generics.RetrieveUpdateDestroyAPIView): queryset = Image.objects.all() serializer_class = ImageSerializer
URL patterns
url(r'^image/$',views.ImageList.as_view(),name='image_list'), url(r'^image/(?P<pk>[0-9]+)/$',views.ImageDetail.as_view(),name='image_detail')
This is just part of the whole system. I want to upload images using RESTAPI and then upload it to amazon s3 and then get the url and save it in the image_path field of the model image. I saw previous solutions for uploading files using REST ( like this ), but nothing worked for my case. Can anyone suggest how I can do this?
python django django-rest-framework amazon-s3
the_unknown_spirit
source share