BeginnerCoder

Lesson 18 — Mini project: blog logic

Combine filter and sort

A blog home page shows published posts, newest first. That is two steps you already know: filter (pub is True) and sort by date descending. In Django: Post.objects.filter(pub=True).order_by("-d").

sorted(rows, key=lambda r: r["score"], reverse=True)

Note: the exercise runs in your browser without Django installed, so it is a small plain-Python simulation of what Django does for you.

Why it matters: real features are small steps combined — this exact query runs on most blogs in the world.

Want it another way?
Task

Build pub (published posts, newest first) and print their titles.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Django Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.