Last active
October 16, 2020 06:45
-
-
Save jadhavmanoj/ac854fb54454cb2b68775f3f866cbe56 to your computer and use it in GitHub Desktop.
Call DRF viewset pythonically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.request import Request | |
from django.http import HttpRequest | |
from django.contrib.auth.models import User | |
from apps.base.views import SampleViewSet | |
django_request = HttpRequest() | |
# create HTTP request skipping token here | |
django_request.method = 'GET' | |
drf_request = Request(django_request) | |
# take user / required params | |
p = User.objects.first() | |
drf_request.user = p | |
data = SampleViewSet() | |
# call here custom action or function | |
data.for_org(request=drf_request) | |
# Hope this will usefull |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment