I am using django rest framework for rest api. I am trying to work on mutiple image upload and associate those multiple images to property. However my browsable api does not show form to upload the images so i can test if my code works or not. How can i upload multiple image and associate them to property?
class Property(models.Model):
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
address = models.CharField(_('Address'), max_length=140)
rooms = models.PositiveSmallIntegerField(_('Rooms'))
class Gallery(models.Model):
property = models.ForeignKey(Property, related_name="gallery")
caption = models.CharField(null=True, blank=True, max_length=80)
image = models.ImageField(upload_to="properties/rooms/")
class GallerySerializer(serializers.ModelSerializer):
class Meta:
model = Gallery
fields=('id', 'caption', 'image', )
class PropertySerializer(serializers.ModelSerializer, EagerLoadingMixin):
_SELECT_RELATED_FIELDS = ['owner', ]
_PREFETCH_RELATED_FIELDS = ['property_type',]
gallery = GallerySerializer(many=True)
class PropertyGallery(APIView):
serializer_class = GallerySerializer
parser_classes = (FileUploadParser,)
def put(self, request, property_id=None, format=None):
serializer = self.serializer_class(data=request.data, partial=True)
if not serializer.is_valid():
return Response(serializer.errors, status= status.HTTP_400_BAD_REQUEST)
else:
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
url(r'^upload/images/(?P<property_id>[0-9]*)/$', views.PropertyGallery.as_view(), name='property-gallery'),
