16. Administration in Django

Página 90

Django's administration module is one of the most powerful features of this framework. It offers a ready-to-use interface that allows site administrators to create, read, update and delete records in the database. This module is highly customizable and can be tailored to meet the specific needs of any project. In this chapter, we will discuss in detail about administration in Django.

To start using the administration module, you first need to create a superuser. The superuser has all permissions and can do anything on the site. To create a superuser, you can use the 'createsuperuser' command in the terminal. After creating the superuser, you can access the administration interface by visiting '/admin' in your website URL.

The Django administration interface is built on the ModelAdmin concept. A ModelAdmin is a class that defines how a model should be displayed in the admin interface. For each model that you want to manage through the administration interface, you need to create a corresponding ModelAdmin class.

A ModelAdmin class defines a series of options that determine how the model is displayed. For example, you can specify which template fields should be displayed in the list of records, which fields should be used for searching, and which fields should be used to filter the list of records. You can also specify the order in which the fields are displayed, and whether they should be editable or not.

In addition, a ModelAdmin class can also define custom actions. Actions are operations that can be performed on one or more records selected from the list. For example, you can define an action that deletes all selected records, or an action that changes a specific field on all selected records.

Django also allows you to customize the appearance of the admin interface. You can change the colors, fonts and layout of the interface. You can also add your own logo and header. To customize the appearance, you need to create a CSS stylesheet file and include it in the Django configuration.

Finally, it's worth mentioning that Django's admin module is fully internationalized. This means you can translate all the admin interface strings into any language you want. To do this, you need to create translation files for each language and include them in your Django configuration.

In short, Django's administration module is a powerful tool that can save you a lot of time and effort in managing sites. It offers an out-of-the-box interface that is highly customizable and easy to use. If you're building a site with Django, you should definitely consider using the admin module.

Finally, it's important to remember that while Django's admin module is a powerful tool, it's not intended to be used as an end-user interface for your site's users. It is designed to be used by site administrators to manage site content and settings. For end users, you must create your own views and forms.

We hope this chapter has provided a useful overview of administration in Django. In the next chapter, we'll discuss creating views and forms for end users.

Now answer the exercise about the content:

What is the role of the Django admin module?

You are right! Congratulations, now go to the next page

You missed! Try again.

Next page of the Free Ebook:

9117. Views in Django

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text