File picker from DRF's UI

93 views
Skip to first unread message

Patrick Tchankue

unread,
Apr 24, 2015, 11:48:13 AM4/24/15
to django-res...@googlegroups.com
I am using DRF it works fine but there is no option to upload a file from the native UI. I have to use a tool such as Postman to achieve it. 
Is there a way I can do it with DRF's native UI?
I created a serializer with ImageField and FileField but I still don't get a file picker.

Joseph Wayodi

unread,
Apr 24, 2015, 10:34:01 PM4/24/15
to django-res...@googlegroups.com
Do you mean from the browsable API? I just tested (on version 2.4.4,
though), and can see a file picker.

Could we see your serializer's code?

Joseph.

Patrick Tchankue

unread,
Apr 26, 2015, 6:51:58 AM4/26/15
to django-res...@googlegroups.com

Hi

I tried this by setting a method to a specific endpoint that will allow me to get and post details about users

My serializer looks like this
Class PersonSerializer (serializers.Serializer):
....
picture = serializers.ImageField (required=false)

In my code to list and add a user, I use PersonSerializer.

Can you perhaps send me a working code so ghat I will see what is missing in mine.

Regards

--
You received this message because you are subscribed to a topic in the Google Groups "Django REST framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-rest-framework/Jv9N2wf0fi8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joseph Wayodi

unread,
Apr 26, 2015, 8:04:16 AM4/26/15
to django-res...@googlegroups.com
This shows the file-picker widget in the browsable API:

# serializers
Class PersonSerializer (serializers.Serializer):
picture = serializers.ImageField (required=False)

# viewsets
class PersonViewSet(viewsets.ModelViewSet):
queryset = models.Person.objects.all()
serializer_class = serializers.PersonSerializer

# urls
router.register(r'people', viewsets.PeopleViewSet)
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Patrick Tchankue

unread,
Apr 28, 2015, 3:31:29 AM4/28/15
to django-res...@googlegroups.com
Hi Joseph,

Thanks for your input. Our approaches are fundamentally different. I used the function-based view, but I don;t think it will be a problem.

#serializers.py
class PersonSerializer(serializers.Serializer):
name = serializers.CharField(required=True)
picture = serializers.ImageField(required=False)
audio = serializers.FileField(required=False)

#views.py
@api_view(['GET', 'POST'])
def person_list(request):

if request.method=='GET':
persons = Person.objects.all()
print persons
serializer = PersonSerializer(persons, many=True)
return Response(serializer.data)

#urls.py
url(r'^api/persons/$', 'people_app.views.person_list'),

I tried a Class-based view approach but I still don't see the picker :(

Patrick Tchankue

unread,
Apr 28, 2015, 11:30:19 AM4/28/15
to django-res...@googlegroups.com
Hi Joseph,

I refactors my code using viewsets and I can see the picker now. Thank you very much for sharing your knowledge with me.

Regards,
Patrick


On Friday, April 24, 2015 at 5:48:13 PM UTC+2, Patrick Tchankue wrote:

Joseph Wayodi

unread,
Apr 28, 2015, 6:57:05 PM4/28/15
to django-res...@googlegroups.com
It's good to hear that you got it working.

You're most welcome.
Reply all
Reply to author
Forward
0 new messages