2๐
โ
As Daniel mentionnned, you should just override the get_queryset method from your view. From there you can pass your parameters you got from the url.
class DuperView(GenericApiView, ListModelMixin):
def get_queryset(self):
year = self.kwargs.get('year')
month = self.kwargs.get('month')
return DuperModel.dupers.filter(month=month, year=year)
I have used the GenericApiView to add the get_queryset method. You can then add the mixins you need for your API. In this case, I added the ListModelMixin, that implement a get method to retrieve a list of elements.
Also you should reference your parameter in your urls :
urlpatterns = [
url(r'^(?P<year>[0-9]{4})/(?P<month>[0-9][0-9]{1,2})/test/$',
]
๐คF. Caron
Source:stackexchange.com