diff --git a/cmp/views.py b/cmp/views.py index c1acb42..96867e3 100644 --- a/cmp/views.py +++ b/cmp/views.py @@ -568,17 +568,16 @@ def soldier(request, soldier_id): context = { "soldier": soldier, "cemetery_map": cemetery_map } return render(request, "cmp/soldier.html", context) - def index(request): - post = request.POST - if post: - try: - search_term = str(post.get("name")) - except ValueError: - print("woo") - - surname = request.POST.get('name') + if request.method == 'POST': + surname = request.POST.get('name', '') soldiers = Soldier.objects.filter(surname__icontains=surname).order_by('surname') - return render(request, 'cmp/soldier-results.html', {'soldiers': soldiers}) + + # Pagination + paginator = Paginator(soldiers, 10) # Show 10 soldiers per page + page_number = request.GET.get('page') + page_obj = paginator.get_page(page_number) + + return render(request, 'cmp/soldier-results.html', {'page_obj': page_obj}) else: return render(request, 'cmp/index.html') \ No newline at end of file diff --git a/templates/cmp/soldier-results.html b/templates/cmp/soldier-results.html index fbef9a8..6ba468f 100644 --- a/templates/cmp/soldier-results.html +++ b/templates/cmp/soldier-results.html @@ -4,7 +4,7 @@
{% block content %} -{% if soldiers %} +{% if page_obj %}
diff --git a/templates/cmp/soldier.html b/templates/cmp/soldier.html index 9713e90..c7ccc0b 100644 --- a/templates/cmp/soldier.html +++ b/templates/cmp/soldier.html @@ -3,11 +3,11 @@ {% block title %}Soldier{% endblock %} {% block content %} -
+
The badge of the Royal Military Police -
-

Corps of Military Police

+

Corps of Military Police

+

Soldier Record