Previous Page Next Page

Adding, Modifying, and Viewing Objects in the Admin Interface

Django's admin interface provides a versatile and dynamic method of administering objects on your website. You can add, modify, and delete objects from the admin interface.

Typically, most objects are added programmatically through a series of web forms and application code. However, often it is useful to be able to quickly view, add, or modify an object from the admin interface.

The admin interface contains a number of predefined views. The main page, shown in Figure 3.3, has three main parts: the title bar, the site administration table, and the Recent Actions list. The title bar at the top displays the site name, a login welcome message, and links to change the password and log out. The Recent Actions list is a history of events that have taken place on the admin interface.

The admin interface is easy to navigate. The Add link allows you to add objects, and the Change link allows you to modify existing objects.

Most of the work is done from the site administration table. In the Auth section, you can enter users and groups. These users are tied into Django's authentication system. In the Sites section, you can enter domain names that the Django server will service. Applications that are enabled in the admin interface appear below Sites.

Try It Yourself: Add and Modify an Object Using the Admin Interface

In the preceding section, you enabled the People model in the admin interface, and it appeared on the main page of the admin interface. In this section, you will use the admin interface to add a Person object to the database.

Follow these steps to open the admin interface and add a Person object and then modify it:

1.
Start the development server.

2.
Log in to the admin interface using a web browser.

3.
From the admin interface (refer to Figure 3.3), click the Add link next to Persons to bring up the add form, shown in Figure 3.4.

Figure 3.4. Add form for a Person object in Django's admin interface.


4.
Enter a name and description, and click the Save button. The new object should appear in the Person list, as shown in Figure 3.5.

Figure 3.5. Object list of Person objects in Django's admin interface.


5.
Click the name link under Person that you just created to bring up the edit form, as shown in Figure 3.6.

Figure 3.6. Update form for a Person object in Django's admin interface.


By the Way

The edit form looks similar to the add form, but notice that it has two additional links. The Delete link at the bottom left is used to delete the object. The History link at the upper right lists changes that have been made to the object.

6.
Change the description, and click the Save button.

7.
Click the name link under Person again to bring up the edit form (see Figure 3.6). Click the History link to see the history of changes to the object, as shown in Figure 3.7.

Figure 3.7. History list for a Person object in Django's admin interface.


Did you Know?

Notice the navigation links, Home > Persons > Brad Dayley > History, below the title bar in Figure 3.7. These are quick links back to previous pages that you navigated. These are almost always present in the admin interface and can speed up navigation.


Previous Page Next Page