How to allow only GET and DELETE methods in a ViewSet

2,086 views
Skip to first unread message

Alessandro Pelliciari

unread,
Feb 17, 2014, 4:42:22 PM2/17/14
to django-res...@googlegroups.com
Hi,

DRF is really awesome.

I'm struggling with a thing: allow only certain methods for a ViewSet (for example, GET and DELETE, just to pick two random methods).

I really like ViewSet and i don't want to switch to generic APIView.

I know that i might override create(), update() etc method in ViewSet throwing a 405 but i think there must be a smarter way.

Can you help me?

Thanks

Alessandro

Massimiliano Pippi

unread,
Feb 17, 2014, 5:19:56 PM2/17/14
to django-res...@googlegroups.com
On Mon, Feb 17, 2014 at 10:42 PM, Alessandro Pelliciari
<isac....@gmail.com> wrote:
> I know that i might override create(), update() etc method in ViewSet
> throwing a 405 but i think there must be a smarter way.
>
You can build your own ViewSet deriving from a proper set of mixins,
something like:

class MyGetDeleteViewSet(mixins.RetrieveModelMixin,
mixins.DestroyModelMixin, GenericViewSet):
pass


Ciao

--
M.

http://2014.djangovillage.it/ :: http://tinkergarage.it/

Alessandro Pelliciari

unread,
Feb 17, 2014, 5:26:39 PM2/17/14
to django-res...@googlegroups.com
Thanks, it's clear now!!


(Grazie :))





--
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/GOHR82y_Nd8/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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages