Hello Micah, My view is too commplicated. The q and the pathologyid ( I actually have two other retrievals that also appended with these) are all appended into the "list". What I need to figure out is how to send the "list" to it's own dictionary, which I can then retrieve with a new view and use that view for the pagination. I can see that the pagination works better with a simple retrieval. Can you tell me how to create a new object from "list" that can be retrieved in a new view?
Thanks. On Mar 11, 10:20 pm, Micah Ransdell <mjr...@gmail.com> wrote: > Jesse, > > The error you are getting is from "q" not being in your post > QueryDictionary. This happens because when you click next you are not > rePOSTing the q variable. Either you can put the q variable into an input > box and POST it again by making your next link a submit button, or you could > change q to a querystring parameter and use request.GET to retrieve it. This > makes it easier to pass on to future pages in your search by putting it into > the querystring for your next link as well. > > I have solved this by putting another variable in my next link like this: > > {% if page_obj.has_next %} > <a href="{% url search %}?q={{ request.REQUEST.q }}&page={{ > page_obj.next_page_number }}">next</a> > {% endif %} > > Micah > > On Wed, Mar 11, 2009 at 12:51 PM, Jesse <adles...@gmail.com> wrote: > > > 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 django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---