Hide or filter form field on POST/PUT forms API views

102 views
Skip to first unread message

David Kuhn

unread,
Sep 21, 2012, 10:53:21 AM9/21/12
to django-res...@googlegroups.com
Is it possible to hide or filter options for particular fields from the generic POST or PUT forms when viewing the API in a browser? 

Some of my objects have a foreign key to a user field and I'd prefer if users couldn't browse through the total list of users on the site. I also have some models where I'd simply prefer to hide a field altogether as it automatically gets set in my save method. I've already hidden these things in the Django admin so I'd like to do the same for the API forms.

Cheers,
Dave

Tom Christie

unread,
Sep 25, 2012, 5:34:08 AM9/25/12
to django-res...@googlegroups.com
That's not possible right now, no.

David Kuhn

unread,
Sep 25, 2012, 10:17:56 AM9/25/12
to django-res...@googlegroups.com
Thanks for the reply Tom. I'd be happy to write a patch to do that, though before I get too involved is there any particular way you'd like to see that sort of thing done?

Dave

Tom Christie

unread,
Sep 25, 2012, 10:37:55 AM9/25/12
to django-res...@googlegroups.com
> I'd be happy to write a patch to do that

Thanks Dave,

  Actually REST framework 2.0 is dues to be released pretty soon, and the situation will be a little different then.

> I also have some models where I'd simply prefer to hide a field altogether as it automatically gets set in my save method.

Right now the codebase uses a slightly weird munging of forms for deserialization and the browseable api, and seperate serializers for serialization.
With 2.0 the serialization API is totally reworked (eg. see tutorial part 1 of the docs-in-progress)
I think the `readonly` flag on the fields (in 2.0) should cover that use case.

Cheers,

  Tom

Vlad Lep

unread,
Jul 22, 2016, 8:07:13 AM7/22/16
to Django REST framework
Hi,

Is this possible in DRF 3.3.x? I would like to limit the choices in the dropdown and not allow other options to be selected. 

Cheers,
Vlad
Reply all
Reply to author
Forward
0 new messages