I have a URL (urls.py)
from django.conf.urls import patterns, url
from rest_framework.urlpatterns import format_suffix_patterns
from rds import views
urlpatterns = patterns('',
url(r'^markit/cdxcomposites/$', views.File_List.as_view()),
url(r'^markit/cdxcomposites/(?P<pk>[0-9]+)/$', views.File_Detail.as_view()), 'cdxcomposites_date'),
)
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['csv', 'json', 'raw', 'xml', 'yaml'])
And I'm trying to use the following view (views.py) -
class File_List(mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView):
queryset = cdx_composites_csv.objects.using('markit').all()
serializer_class = CDX_compositesSerializer
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
to be able to filter by the model field 'Date'
http://localhost:8080/markit/cdxcomposites/?Date=2014-06-26&format=xml
It never seems to filter always returning all results.
I've tried all the samples provided here -
http://www.django-rest-framework.org/api-guide/filtering#overriding-the-initial-queryset
But nothing seems to be taking. I've tried scrapping the mixins and doing a basic class based view and still no dice.
I know I'm missing something obvious but I'm unsure what.
For example doing the most simple of views -
class File_List(generics.ListAPIView):
serializer_class = CDX_compositesSerializer
def get_queryset(self):
"""
This view should return a list of all the purchases for
the user as determined by the username portion of the URL.
"""
Date = self.kwargs['Date']
return cdx_composites_csv.objects.using('markit').filter(Date__Date=Date)
results in the error -
KeyError at /markit/cdxcomposites/
'Date'