Django rest framework nested viewsets and routes

625 views
Skip to first unread message

Stefano Tranquillini

unread,
May 5, 2014, 11:53:09 AM5/5/14
to django-res...@googlegroups.com
Ciao all, one question:

Can i nest the viewsets and create routes that takes pk as parameters of the url?

basically:

class TaskView(viewsets.ModelViewSet):
    model = Task

this works fine and it's mapped to the task/ url, so task/1/ gives the data of the task with id 1. now, i want to create an instance of the task, having CRUD operations as for the task, so i would like to have

class InstanceView(viewsets.ModelViewSet):
        model = Instance

mapped to task/{pk}/instance, where pk is the id of the task.

how can i do that? is it possible?
PS: i saw that there are @action and @link but using them i loose the power of having everything made by the framework.

i've posted the question also on SO:
https://stackoverflow.com/questions/23476342/django-rest-framework-nested-viewsets-and-routes

--
Stefano

Kevin Brown

unread,
May 5, 2014, 12:21:07 PM5/5/14
to django-res...@googlegroups.com
Hi Stefano,

I've replied to your question at SO.

http://stackoverflow.com/a/23476882/359284

Depending on what you are looking for, either you will need to use one of the third-party apps (for hyperlinked relations, mainly) or you can just override `get_queryset` if you do not need them (and get the values from `self.kwargs`).
-- 
Kevin Brown
--
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 email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages