What I want is to handle three ViewSet with one URL
respect to the provided request.data
.
Let's make it more clear by diving into code:
Here is my router.py
# vim: ts=4 sw=4 et
from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter
from . import viewsets
router = DefaultRouter()
router.register(r'endpoint', viewsets.MyViewSet, 'my-viewset')
notification_urls = [
url(r'^', include(router.urls)),
]
Question1:
Is it possible to handle three ViewSet
with one URL?
For example, according to the data that has been sent, I want to select dynamically a different ViewSet instead of assigned MyViewSet
.
---> /endpoint/ ---- | request.data['platform'] == 1 ----> ViewSet1
| request.data['platform'] == 2 ----> ViewSet2
| request.data['platform'] == 3 ----> ViewSet3
and I know that I can call other ViewSet's methods in a MyViewSet
something like this Question but this is really a messy one.
Question2:
Is it possible to dynamically pass extra params respect to the data that has been sent to a ViewSet?
For example, according to the data that has been sent, I want to pass an extra param into MyViewSet
.
I know that I can do all this stuff in ViewSet initial
method, Like this:
def initial(self, request, *args, **kwargs):
self.set_platform()
super(NotificationViewSet, self).initial(request, *args, **kwargs)
But what I want is to handle this stuff during the MyViewSet
instantiation.
NOTE: Maybe I can handle this by Writing a Middleware
but if there are other options I would really be appreciated for sharing them with me.