I have a working example of a search view based on Vanilla Views (see https://github.com/DanSears/vanilla-views-example). I did have a problem where my view worked with small datasets, but then the view would fail with large datasets because the default queryset is all()). So I worked out the following:
# combine the quote terms to form a modified queryset
def get_queryset(self):
# get the queryset from the parent class
queryset = super(SearchList, self).get_queryset()
# get the search terms from the form controls in the template
my_band = self.request.GET.get('band')
my_publication_year = self.request.GET.get('publication_year')
# return a queryset
if (my_band and my_publication_year):
# return a filtered queryset
return queryset.filter(
band__exact = my_band # foreign key
).filter(
publication_year__exact = my_publication_year
)
else:
# return an empty queryset
return queryset.none()
Basically, if the search terms are not valid, then get_queryset() returns none(). I couldn't find an example with either Vanilla Views or standard Class Based Views that did this.
My question is whether this is a reasonable solution or is there a different way to handle large datasets. I'm asking because I'm taking the scenic route of learning Vanilla Views, then Django-Filter and then finally Django REST Framework. And this approach doesn't seem to work in Django-Filter.
I have a working example of a search view based on Vanilla Views (see https://github.com/DanSears/vanilla-views-example). I did have a problem where my view worked with small datasets, but then the view would fail with large datasets because the default queryset is all()). So I worked out the following:
Basically, if the search terms are not valid, then get_queryset() returns none(). I couldn't find an example with either Vanilla Views or standard Class Based Views that did this.
My question is whether this is a reasonable solution or is there a different way to handle large datasets. I'm asking because I'm taking the scenic route of learning Vanilla Views, then Django-Filter and then finally Django REST Framework. And this approach doesn't seem to work in Django-Filter.
Thanks,
--Dan