Django Practice
Master production-ready Django by solving hands-on challenges, one concept at a time.
Models & Relationships
Unlock the database layer of your applications with this comprehensive module on Django Models & Relationships
Product Model Definition
Products lose data: prices come back wrong, names have no length limit, and nothing records when an item was added. Define a Product model with a bounded name, an exact decimal price, a stock count with a sensible default, an active flag, an auto-set creation time and a readable string form.
Author Book Foreign Key
Books and authors live in unrelated tables, so deleting an author leaves orphaned books. Relate Book to Author so an author's books go with the author and are listed through the author, and add an optional publisher that cannot be deleted while it still has books.
Course Enrollment Links
Students take many courses, courses have many students, and each student has exactly one transcript. Model the many-to-many and the one-to-one, readable from both sides, with at most one transcript per student enforced by the database.
Library Domain Schema
Model a library from scratch: members, books, authors, loans and member cards. Use every relationship kind: books to authors (many-to-many), loans that link a member and a book and carry their own due date, and one card per member, with delete rules and readable string forms throughout.
QuerySets & ORM Basics
Query the database through the ORM: filter, order, shape results, and fetch single objects safely in one query.
Filtered Product Lookups
The product search returns everything no matter what the user asks for. Filter products by a case-insensitive name match and an inclusive price range, leave out inactive items, sort by price then name, and answer in a single database query.
Ordered Result Shaping
A report needs items in the right order, only a few columns, and just the latest rows. Add chainable QuerySet methods that sort by name or newest first, take the top N, and return plain dicts or a flat list of names.
Single Object Retrieval
Detail lookups crash on unknown products and silently pick a random row when names repeat. Fetch single products safely by sku and by name, ignore discontinued items, and answer "any products?" and "how many?" without loading rows.
Catalog Query Toolbox
Support needs one set of catalog answers they can trust. Build query functions for search, newest items, price lists, name lists and single lookups, each skipping inactive products and running exactly one query.
URLs & Views
Route requests with path converters and named URLs, and return safe HTML, redirect, and JSON responses.
Article Routing
Only the home page is routed, so every article URL is a 404. Route articles by id, slug and four-digit year so the view receives typed values and malformed URLs are rejected before any view runs.
Named Routes And Redirects
Links and redirects break every time a URL changes. Name the routes inside an app namespace, build every link from those names, and send old post URLs to their new home with a permanent redirect.
Safe Detail And JSON Views
Product pages need a safe detail view and a JSON endpoint. Return the product page or a 404 for unknown ids, and serve the same product as properly encoded JSON with its price as a two-decimal string.
Recipe Site Views
A recipe site needs its whole request layer built. Add namespaced routes for the list, detail, year archive, JSON API and a legacy redirect, with typed URL arguments, 404s for bad input, and every URL built from its route name.
Templates
Render pages with the Django template language: filters, loops, conditions, includes, and template inheritance.
Rendered Product Page
The product page has no template yet. Render the product from a template with a readable release date, a fallback for a missing manufacturer, a short description teaser and prices that always show two decimals.
Conditional Stock Listing
Every product row in the listing looks the same. Number the rows, alternate their styling, show a sold-out or low-stock badge from a reusable partial, and show a friendly message when the list is empty.
Site Skeleton Inheritance
Every page would need its own copy of the HTML skeleton and navbar. Build a base template with title and content blocks and an included navbar whose links come from URL names, then have each page extend it.
Storefront Pages
A storefront needs its list and detail pages built on a shared layout. Link each product row to its detail page, reuse one stock badge on both pages, format prices to two decimals, and show a teaser in the list and the full description on the detail page.
Django Admin
Run a back office on the admin site: registrations as the access decision, configured change lists, computed columns, inlines, and bulk actions.
Registered Catalog Admin
Register the catalogue models with the Django admin so staff can create, edit and delete records through the interface.
Browsable Change List
Configure a Django admin change list with columns, a computed column, search, sidebar filters and a default order.
Inline Order Editing
Edit order items inline on the order page, show a read-only computed total and add a bulk admin action.
Store Back Office
Configure a complete Django admin back office: change lists with computed columns, search, filters, ordering, inline editing, read-only totals, a bulk action and correct registration scope.
Static & Media Files
Serve the assets that ship with the code and the files users upload, each resolved through its own tag and kept in its own root.
Styled Pages With Static Assets
Serve a stylesheet and a logo through Django's static files: the app static layout and the static template tag instead of hardcoded paths.
Document Upload Handling
Accept a validated PDF upload through a Django form and store it under MEDIA_ROOT, with the multipart encoding the browser needs.
Avatar Image Field
Add an image field with an upload-to path and render the stored image's URL, falling back to a static placeholder.
Gallery Uploads Page
Build a photo gallery end to end: static assets through the static tag, validated image uploads into a dated media path, and a listing with a placeholder fallback.
Class-Based Views
Replace hand-rolled views with generic class-based views: list, detail, create, update and delete, paginated, gated and owner-scoped.
Paginated Article List
Configure a Django ListView with its template, context name, ordering and built-in pagination.
Article Detail And Create
Wire a DetailView and a CreateView with a form class, redirecting to the new object through get_absolute_url.
Scoped Edit And Delete
Restrict UpdateView and DeleteView to the signed-in user's own objects by overriding get_queryset, with login required and defined redirects.
Notes CRUD Application
Build a complete CRUD surface with generic class-based views: paginated owner-scoped list with extra context, detail, create attaching the owner server-side, and scoped update and delete behind a login gate.
About this path
This path covers the core of a Django 5.2 site: models and relationships, QuerySets and the ORM, URLs and views, and templates. You should be able to write basic Python before you start. No earlier Django experience is needed. The templates module renders real pages from your data and ends with a small storefront.
Frequently asked questions
4>What will I practice in this path?
7 modules: Models & Relationships, QuerySets & ORM Basics, URLs & Views, Templates, Django Admin, Static & Media Files and Class-Based Views.
>How many challenges are there, and how hard are they?
28 challenges: 24 easy and 4 medium.
>What does this path run on?
Challenges run on Django 5.2 and Python 3.13.
>Do I need to install anything?
No. Every challenge runs in a browser-based IDE with everything already set up, and your code is graded automatically against a test suite.
