5 Django Admin

 

This chapter covers

  • Using the Django Admin to manage your Model content
  • Creating a superuser
  • Customizing the Django Admin
  • Linking between Model objects in the Django Admin
  • Model Meta properties

This chapter covers the Django Admin, a built-in, web-based tool for managing your object relational mapping (ORM) Model objects. The Django Admin gives you screens to list, add, edit, and delete the objects in the database.

5.1 Touring the Django Admin

In the previous chapter, you learned how to use the ORM to add storage capabilities to your Django site. Along the way, you used two techniques to construct data: the .create() method on a Model object and fixtures. Wouldn’t it be nice if you had a graphical interface to manage your objects? Django comes with a tool that does this for you. The Django Admin is a customizable, web-based interface that allows you to create and modify your Model objects with very little code.

Figure 5.1 shows a Django Admin screen that lists all of the Musician objects in the database. The code I wrote to generate that screen is less than 80 lines long. With it, you have multifield sorting, field search, filtering, custom columns, and all the actions you need to be able to add, update, and delete musicians from the database.

Figure 5.1 Parts of the Musician Listing page in the Django Admin
figure

5.1.1 Creating an admin user

5.1.2 The default Django Admin

5.1.3 Adding your own models

5.2 Customizing a listing page

5.2.1 Sorting and searching

5.2.2 Filtering

5.2.3 New in Django 5: Facets

5.3 Cross-linking between related objects

5.4 Model Meta properties

5.4.1 Sort order

5.4.2 Indexes

5.4.3 Uniqueness

5.4.4 Object names

5.5 Exercises

Summary

sitemap