A
A
Alexander2018-03-23 11:03:19
Django
Alexander, 2018-03-23 11:03:19

How to pull data by URI (DRF)?

Who knows how to get data by uri ?
There is a table in the database and the uri is stored in it: "api/v1/myapp?my_filter=my_value" . I came up with a crutch way, send a GET request and receive data.
Is it possible to feed a ModelViewSet with yuriai and get the data? Or feed the FilterSet with yuriai and get the data?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2018-03-23
@kentuck1213

from django.http import QueryDict
my_obj = MyFilterSet(data=QueryDict("status=show&count=10"), queryset=MyModel.objects.all()).qs

P
Pavel Aksenov, 2018-03-23
@hellmin

I think it was meant

from urllib import parse
from django.urls import resolve

uri = '/api/v1/myapp?my_filter=my_value'
data = parse.urlsplit(uri)
path = data.path
params = dict(parse.parse_qsl(data.query))
viewset = resolve(data.path).func.cls
queryset = viewset.filter_class(data=params).qs

F
Federalt, 2018-03-23
@Federalt

www.django-rest-framework.org/api-guide/filtering
django-filter.readthedocs.io/en/latest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question