The following code is for a search on q and attaches tuples from the
search on another model. The search results are appended together to
create the final data results "list".
def Bypub(request):
query = request.POST['q']
if query:
qset = (
Q(pubtitlestrip__icontains=query) |
)
pubresults = Publication.objects.filter(qset).distinct() #
original
else:
pubresults = []
pathology_id = request.POST['pathology_id'] #original works
p = get_object_or_404(Pathology, pk=pathology_id)
pub1=Publication.objects.filter(pathpubcombo__pathology=p)
for publication in pubresults:
if publication not in list:
list.append(publication) # the object going to template
paginator = Paginator(list, 5)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
publications = paginator.page(page)
except (EmptyPage, InvalidPage):
publications = paginator.page(paginator.num_pages)
return render_to_response('search/searchresults_pub.html', {
"query": query,
"pubresults": pubresults,
'pub1': pub1,
'pathology': p,
'list' : list,
'publications' : publications,
},
context_instance=RequestContext(request)
)
The template:
{% for publication in publications.object_list %}
{{ publication.pubtitle|safe }}
{% endfor %}
{% else %}
No publications found. Please try a different search.
{% endif %}
<div class="pagination">
<span class="step-links">
{% if publications.has_previous %}
<a href="?page=
{{ publications.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ publications.number }} of
{{ publications.paginator.num_pages }}.
</span>
{% if publications.has_next %}
<a href="?page={{ publications.next_page_number }}">next</
a>
{% endif %}
</span>
</div>
Every thing works just fine until I select the link for the "Next"
page. The URL in browser is:
http://127.0.0.1:8000/Search/?page=2
ERROR:
Exception Type: MultiValueDictKeyError
Exception Value:
Key 'q' not found in <QueryDict: {}>
I think when I select "Next" it is returning to the def Bypub, but of
course the q is not there the second time. How do I preserver the
"list" as a dictionary to output to the next page? This might also
answer the other problem I'm having with sending the "list" to a csv
file. I also need some way to store the data for the csv file.
Any help is appreciated. Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---