Skip to content

Commit 1b0fcd8

Browse files
committed
Pull out the home list view into a variable to make the code easier to read
1 parent 5fe6750 commit 1b0fcd8

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

hello/urls.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
from hello import views
44
from hello.models import LogMessage
55

6+
home_list_view = views.HomeListView.as_view(
7+
queryset=LogMessage.objects.order_by("-log_date")[:5], # :5 limits the results to the five most recent
8+
context_object_name="message_list",
9+
template_name="hello/home.html",
10+
)
11+
612
urlpatterns = [
7-
path(
8-
"",
9-
views.HomeListView.as_view(
10-
queryset=LogMessage.objects.order_by("-log_date")[
11-
:5 # :5 limits the results to the five most recent
12-
],
13-
context_object_name="message_list",
14-
template_name="hello/home.html",
15-
),
16-
name="home",
17-
),
13+
path("", home_list_view, name="home"),
1814
path("hello/<name>", views.hello_there, name="hello_there"),
1915
path("about/", views.about, name="about"),
2016
path("contact/", views.contact, name="contact"),

0 commit comments

Comments
 (0)