From 8022588cf5558e2e987b2d25cec42b8522dee0f8 Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Fri, 10 Jul 2020 21:25:16 -0700 Subject: [PATCH] Add pagination to ListView --- places/templates/places/restaurant_list.html | 16 ++++++++++++++++ places/tests/views/test_restaurant.py | 5 +++-- places/views.py | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/places/templates/places/restaurant_list.html b/places/templates/places/restaurant_list.html index 5e0ae3e..6a6a854 100644 --- a/places/templates/places/restaurant_list.html +++ b/places/templates/places/restaurant_list.html @@ -15,5 +15,21 @@

Restaurants

  • No restaurants yet.
  • {% endfor %} + + {% endblock %} diff --git a/places/tests/views/test_restaurant.py b/places/tests/views/test_restaurant.py index ecc6826..24c682f 100644 --- a/places/tests/views/test_restaurant.py +++ b/places/tests/views/test_restaurant.py @@ -3,6 +3,7 @@ from django.urls import reverse from places.models import Restaurant +from places.views import RestaurantListView class TestRestaurantListView(TestCase): @@ -10,11 +11,11 @@ class TestRestaurantListView(TestCase): desired_url = "/places/restaurants/" desired_name = "places:restaurant-list" - desired_restaurant_count = 25 + desired_restaurant_count = RestaurantListView.paginate_by @classmethod def setUpTestData(cls): - for i in range(cls.desired_restaurant_count): + for i in range(cls.desired_restaurant_count * 2): Restaurant.objects.create( name=f"Chipotle {i}", address=f"Bogus {i}", diff --git a/places/views.py b/places/views.py index fc308bb..95905ec 100644 --- a/places/views.py +++ b/places/views.py @@ -16,6 +16,7 @@ class HomeView(TemplateView): class RestaurantListView(ListView): model = Restaurant ordering = ["name"] + paginate_by = 15 context_object_name = "restaurant_list"