Skip to content

Instantly share code, notes, and snippets.

@jadhavmanoj
Last active October 16, 2020 06:45
Show Gist options
  • Save jadhavmanoj/ac854fb54454cb2b68775f3f866cbe56 to your computer and use it in GitHub Desktop.
Save jadhavmanoj/ac854fb54454cb2b68775f3f866cbe56 to your computer and use it in GitHub Desktop.
Call DRF viewset pythonically.
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