Enhancing models for the admin
Here is an example that enhances the model's admin
for better presentation and functionality. You can look at the difference between the two following screenshots to see how a few lines of code can make a lot of difference:
The default admin list view for the sightings model
After the admin
customizations explained in this section are made, the same information will be presented in a much more accessible manner, as shown in the following screenshot:
The improved admin list view for the sightings model
The admin
app is smart enough to figure out a lot of things from your model automatically. However, sometimes the inferred information can be improved. This usually involves adding an attribute or a method to the model itself (rather than to the ModelAdmin
class).
Here is the enhanced Sightings
model:
# models.py class Sighting(models.Model): superhero = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE) power = models.CharField...