Wednesday 1:20 p.m.–4:40 p.m.
Delving into the Django Admin
- Audience level:
- Web Frameworks
The admin interface is widely considered a "killer feature" of Django. At its most basic, you can just register all your models and be on your way, but there's so much more available within Django's admin. This tutorial takes you step by step through the creation and progressive improvement of an admin interface for a fictional library (all code is publicly available).
**Overview** It is a truth universally acknowledged that the admin is an important component of the Django framework, and knowing how to make efficient use of it can save you days or weeks of development. The Django tutorial is a great place to take your first steps with the admin, but it can often take a bit of searching to learn how to use some of the more advanced features. The goal of this tutorial is to bridge the gap between the Django tutorial and the reference documentation of the Django admin by using real examples. We will use a fully-functional (though fictional) Django project to build an admin interface to support the librarians at a local library. The interface will allow them to add and edit patrons and resources (books, CDs, DVDs, etc.) as well as manage fines for overdue items. They will be able to make comments on various models as well. The tutorial begins with a discussion of what a library might need in terms of an administrative interface for the librarians. We then cover the models that are available in our demonstration project (https://bitbucket.org/jacinda/admin-library). We then proceed through a commit-by-commit progression of our repository that demonstrates the evolution of this admin interface. While not required, students will get more out of the tutorial if they have a computer with them that is capable of running the code in the admin-library repository. The repository includes the necessary files to use a virtual machine and vagrant or can be setup easily within a virtualenv running on the metal of most systems. Students are expected to have some familiarity with Django but even novices will be able to get a lot of information from this tutorial (particularly the first half). **Ground to Be Covered** We move quickly through some more basic "review" examples that more experienced Django users will be familiar with, like changing the default URL, the title text and some idiosyncrasies of using Django's AbstractUser with the admin. We also cover adding models, modifying the display of those models, changing field / fieldset orders, adding help text and a laundry list of "basic hygiene" admin tasks. The bulk of the tutorial then covers more intermediate / advanced topics within the admin, including the use of custom readonly fields to allow certain staff members the ability to edit certain fields while restricting other staff members, the potential performance impact of including different fields in list_display, and how to use custom filters, views, and templates to add additional functionality. Based on audience interest and timing, the tutorial will cover audience questions about the admin and either try to demonstrate answers in real time or provide a link later to an example.
No handouts have been provided yet for this tutorial