StaffCoder
Django
DjangoDjango 5.2Python 3.13
18 modules · 72 challengesSign up
Module 5 · Django Admin

Registered Catalog Admin

easyDjango AdminModel Administration100%3 of 3 solved

Problem statement

Django ships a complete back office for the catalogue - browsable lists, add and edit forms, delete confirmation, all generated from the models - and the store is not using any of it. Staff edit prices by opening a shell and typing ORM lines, because /admin/ knows about no models at all. app/admin.py is where a model is introduced to the admin site, and it is empty. Two of the three models belong to staff; the third does not.

Requirements

Implement:

  • the admin registrations in app/admin.py

The following files are already implemented and provided: app/models.py, app/views.py, app/urls.py and project/urls.py. Category is a catalogue section with a name. Product is a catalogue item with name, sku, price and a category foreign key. ImportBatch is bookkeeping for the nightly feed, with filename and started_at. The admin site is already mounted at /admin/ and django.contrib.admin is already installed, so only app/admin.py is missing.

1. The two models staff manage

  • Category and Product are both known to the admin site, so both appear on the admin index at /admin/ with links to /admin/app/category/ and /admin/app/product/.
  • Each of them has a working change list at /admin/app/<model>/, which answers 200, plus the add form, the edit form and the delete confirmation the admin builds from the model itself:
    • POST /admin/app/product/add/ with a valid name, sku, price and category redirects and stores the product.
    • POST /admin/app/product/<pk>/change/ saves the edited values.
    • POST /admin/app/product/<pk>/delete/ with post=yes removes the row.
    • Category round-trips the same way through its own add and delete pages.

2. The internal model stays out

  • ImportBatch is written by the nightly feed and read by nobody through a form, so the admin site is never told about it.
  • Its name does not appear on the admin index, and its admin URLs answer 404 - both /admin/app/importbatch/ and /admin/app/importbatch/<pk>/change/.

Notes

  • Only app/admin.py changes.
  • Registering a model introduces it to the admin site, which then builds the model's pages from the model itself.
  • Registration is also the whole access decision: a model nobody registers has no admin pages at all, which is the right answer for a table staff should not be editing by hand. Nothing else has to be switched off.
  • Do not configure columns, search, filters or ordering yet; a bare registration is the whole task.

More in Django Admin

See the module
Browsable Change ListConfigure a Django admin change list with columns, a computed column, search, sidebar filters and a default order.100%3 of 3 solvedeasyInline Order EditingEdit order items inline on the order page, show a read-only computed total and add a bulk admin action.100%3 of 3 solvedeasyStore Back OfficeConfigure 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.100%3 of 3 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.