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.
