Alright, here is what I want to do:
A user sees a number of assignments in a table, with each assignment paginated using paginator. A user can input a number in a field and click "go", he is then taken to the page.
Here's my code so far:
View:
def home(request):
if request.user.is_authenticated():
assignments = show_assignments(request)
form=GoToForm(request.POST or None)
if request.POST and form.is_valid():
form = form.cleaned_data
assignment = form["assignment"]
page = form["page"]
return HttpResponseRedirect("/coding/assignment/%i/?page=%i") % (assignment, page)
return render(request, 'account.html', {'assignments':assignments, 'form':form})
Template:
{% for assignment in assignments %}
<tr>
<td><a href="{% url 'coding:assignment' assignment.id %}">
{{ assignment.country }}: {{ assignment.start_date }} to {{ assignment.end_date }}</a></td>
<td>{{ assignment.finished_articles }} of {{ assignment.article_num}} articles finished </td>
<td><a href="/coding/assignment/{{ assignment.id }}/?page={{ assignment.last_updated}}">Start where I left off</a></td>
<td>
<form id="form" action="" method="post" accept-charset="utf-8">
{% csrf_token %}
Jump to page {{ form.page }}
<input type="hidden" name="" value="{{ assignment.id }}" id="id_assignment">
<input type="submit" value="Go">
</form>
</td>
</tr>
{% endfor %}
This isn't working. Is this because I need to use formsets (because I have multiple GoToForms on one page), or is the HttpResponseRedirect not working?