http://docs.djangoproject.com/en/dev/ref/contrib/admin/
Django’s administration page will let us create posts, authors, and topics. But we need to tell the admin page about our new app.
Create a new file in the “postings” directory, and call it “admin.py”.
from django.contrib import admin
from Blog.postings.models import Post, Author, Topic
admin.site.register(Post)
admin.site.register(Author)
admin.site.register(Topic)
You’ll need to cancel the runserver (CTRL-C) and restart it to get Django to recognize that there’s a new file in the postings directory. But once you do, you can go to http://localhost:8000/admin/postings/ to edit your posts, authors, and topics.
Now that you’ve got a model and an administration screen, go ahead and add H. L. Mencken’s “War” essay and George Orwell’s “Atomic Bomb” essay.
- Customizing the admin
- A couple of things immediately come to mind. First, the slug will almost always be very similar to the title. Second, while the list of posts is perfectly serviceable, it could be a lot more useful. When we have a hundred or a thousand posts, it’ll be nice if we can see the date, author, and other items in the list of posts.
- Create your administration models: Filters
- That’s already a lot better, but we can make the admin page even more useful. There are three very useful filters that help us quickly focus on the posts we want to see. Below list_display, add:
- Editable fields
- Some fields, such as the “live” field, it may make sense to be able to do more than one at a time. Add this line to the PostAdmin class:
- Pre-populated fields
- The slug is usually the title but without spaces and other special characters. We can tell Django to try and handle this for us:
- Customize Author and Topic
- Go ahead and make a custom ModelAdmin for Author and Topic also: