There's one crucial part we haven't done yet. Let's add our own models to the admin site, so we can add, change and delete objects in our custom database tables using this nice interface. We'll continue the books
example from Chapter 4, Models, where we defined three models: Publisher, Author, and Book. Within the books
directory (mysite/books
), startapp
should have created a file called admin.py
, if not, simply create one yourself and type in the following lines of code:
from django.contrib import admin from .models import Publisher, Author, Book admin.site.register(Publisher) admin.site.register(Author) admin.site.register(Book)
This code tells the Django admin site to offer an interface for each of these models. Once you've done this, go to your admin home page in your web browser (http://127.0.0.1:8000/admin/
), and you should see a Books section with links for Authors, Books, and Publishers. (You might have to stop...