Hi,
I have form on a search page called SearchForm where the user selects items to search.
The rest part creates a URI which appears as below from the selected items to search.
I'm trying to write a classview in views.py to get the URI parameters, then
fashion a query to place those in an object_list for viewing in a search results template.
views.py
class SearchResultsView(django.views.generic.ListView):
template_name = 'ephemera/searchresults.html'
model = Item #my model class
def get_queryset(self, **kwargs):
form = SearchForm()
choose_collection = self.request.GET.get('choose_collection')
user_input = self.request.GET.get('user_input')
choose_item = self.request.GET.get('choose_item')
object_list = self.model.objects.filter(collection__icontains = choose_collection).filter(choose_item__icontains = user_input) #XXX
return object_list
I can't seem to figure out how to pass the choose_item get variable to the filter. Django complains cannot resolve keyword 'choose_item' into field. The correct field is 'title' but I won't know that until the user selects one of the choices from the form pull down menu.
The following query works fine directly on sqlite, but I can't seem to figure out how to do it in the class view.
select * from ephemera_item where collection = 'MACMILLAN' AND title = 'Guitar Builder';
Could be my basic approach is bad too, because I'm only just starting out with this.
Thank you for any advice.
Regards,
Bob