It's all firing well, thanks for the heads up and the help. On May 11, 9:26 am, Nuno Maltez <nuno.li...@gmail.com> wrote: > Great, Just make sure you don't end up with multiple "page" arguments > on your query string when navigating through the results (click next; > click next again...). > > Nuno > > > > On Tue, May 11, 2010 at 2:41 PM, Nick <nickt...@gmail.com> wrote: > > The POST thing was the result of late night meltdowns and desperation. > > I tend to just try stupid things when i'm working through an issue > > like this, just seeing what the application is capable of doing. I've > > switched it all back to GET. > > > I found the answer around 1 this morning. You are exactly right, I > > needed to capture the query string and place it in the "next" and > > "previous" page links. Here's how I went about doing that, just in > > case someone else runs into this issue: > > > query_string = request.GET.copy() > > > and then in the dict: > > > 'query_string': query_string.urlencode() > > > On May 11, 4:46 am, Nuno Maltez <nuno.li...@gmail.com> wrote: > >> You need to pass the current search paramters in your query string > >> (?party=D&q=<txt>&page=<num> ) when you create the links to all the > >> pages, and you need to be able to retrieve them from request.GET in > >> order to recreate the object list (reps) when rendering a specific > >> page (any particular reason why are you using POST in the search > >> form?). > > >> hth, > >> Nuno > > >> On Tue, May 11, 2010 at 1:58 AM, Nick <nickt...@gmail.com> wrote: > >> > I'm trying to paginate results from a search with multiple options. > >> > The only problem is, once I hit the next button it clears the query > >> > and I'm left paginating all the objects in the DB. > > >> > Here is my view: > > >> > def filter_search(request): > >> > if request.POST: > >> > reps = Rep.objects.all() > >> > else: > >> > reps = [] > >> > query = request.POST > >> > if 'q' in request.POST: > >> > q = request.POST.get('q', '') > >> > qset = ( > >> > Q(Last_Name__icontains=q) | Q(First_Name__icontains=1) > >> > ) > >> > reps = reps.filter(qset) > >> > else: > >> > q = [] > >> > if len(q): > >> > qlist = q > >> > else: > >> > qlist = [] > >> > if 'party' in request.POST: > >> > party = request.POST.getlist('party') > >> > reps = reps.filter(Party__in=party) > >> > else: > >> > party = [] > >> > if len(party): > >> > plist = party > >> > else: > >> > plist = [] > >> > paginator = Paginator(reps, 15) > >> > results = paginator.count > >> > try: > >> > page = int(request.POST.get('page', '1')) > >> > except: > >> > page = 1 > >> > try: > >> > repList = paginator.page(page) > >> > except (EmptyPage, InvalidPage): > >> > repList = paginator.page(paginator.num_pages) > >> > finalq = request.POST > >> > return render_to_response("Government/search.html", { > >> > 'reps': repList, > >> > 'query': query, > >> > 'plist': plist, > >> > 'qlist': qlist, > >> > 'results': results, > >> > 'finalq': finalq > >> > }) > > >> > Here is my tpl: > > >> > <form action="" method="POST"><br /> > >> > <input type="text" name="q"><br /> > >> > Democrat <input type="checkbox" name="party" value="D"> > >> > Republican <input type="checkbox" name="party" value="R"> > >> > <input type="submit" value="Search"> > >> > </form> > > >> > {% if query %} > >> > <h3>Your search for {% if qlist %} <span>{{ qlist}}</span> {% endif %} > >> > {% if plist %} {% for p in plist %} {% if forloop.first %} <span>Party > >> > ({{ p }})</span> {% else %} & <span> Party ({{p}})</span> {% endif %} > >> > {% endfor %}{% endif %} returned <span>{{ reps.paginator.count }}</ > >> > span> result(s)</h3> > >> > <ul> > >> > {% for object in reps.object_list %} > >> > <li>{{ object.Position }} {{ object.First_Name }} > >> > {{ object.Last_Name }} <a href="http://django.newsok.com/government/ > >> > reps/{{ object.Last_Name }}_{{ object.First_Name}}">view more</a></li> > >> > {% endfor %} > >> > </ul> > > >> > <div id="pagination"> > >> > {% if reps.has_previous %} > >> > <a class="activePrev" > >> > href="&page={{ reps.previous_page_number }}">Previous</a> > >> > {% else %} > >> > <a class="nullPrev">Previous</a> > >> > {% endif %} > > >> > {% if reps.has_next %} > >> > <a class="activeNext" href="&page={{ reps.next_page_number }}">Next</ > >> > a> > >> > {% else %} > >> > <a class="nullNext" href="">Next</a> > >> > {% endif %} > >> > </div> > > >> > That href is the cause of the problem, how do I pass a page to the url > >> > without resetting the query? > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups "Django users" group. > >> > To post to this group, send email to django-us...@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > django-users+unsubscr...@googlegroups.com. > >> > For more options, visit this group > >> > athttp://groups.google.com/group/django-users?hl=en. > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "Django users" group. > >> To post to this group, send email to django-us...@googlegroups.com. > >> To unsubscribe from this group, send email to > >> django-users+unsubscr...@googlegroups.com. > >> For more options, visit this group > >> athttp://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en.
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.