Curso Django. Panel de Administración IV. Vídeo 19

Curso Django. Panel de Administración IV. Vídeo 19

Introduction to Django Admin Panel and Adding Filters

In this video, the instructor introduces the Django admin panel and explains how to add filters to the panel. The goal is to filter records stored in database tables based on specific criteria.

Adding Filters to the Admin Panel

  • The instructor demonstrates the need for filters by showing a table of articles with different sections. Filtering would be useful to view records from specific sections.
  • To add a filter, a new class needs to be created in the admin file. This class should inherit from admin.ModelAdmin.
  • In the new class, specify the field by which you want to filter using list_filter = ['field_name']. Make sure to use the exact field names as they appear in your table.
  • Register the new class in admin.site.register function.
  • After saving changes, refresh the browser where the server is running. A filter table will appear on the right side of the admin panel.
  • Clicking on a section in the filter table will display only records from that section.

Benefits of Adding Filters

  • The instructor emphasizes that adding filters is extremely useful when dealing with tables containing many records.
  • While filtering by section is demonstrated, it can also be applied to any other criteria or table.
  • Filtering by date is particularly powerful, allowing users to filter records by specific time periods.
  • The instructor mentions the importance of having a date field in the table and demonstrates how to add records for filtering.

Introduction and Setting up Order Model

In this section, the speaker discusses setting up the order model in the admin panel.

Adding Order Details

  • The speaker starts by adding an internal order number (e.g., 1005) and a date in American notation (YYYY-MM-DD).
  • They mark the order as delivered and save it.
  • Additional orders are added with different dates and delivery statuses.

Viewing Orders in Admin Panel

This section focuses on viewing orders in the admin panel.

Creating "PedidosAdmin" Class

  • To view orders in the admin panel, a new class called "PedidosAdmin" is created, inheriting from admin.ModelAdmin.
  • The desired fields to be displayed are specified using list_display.

Displaying Fields and Saving Changes

  • The fields to be displayed, such as order number and date, are specified within list_display.
  • After saving changes, the admin panel now shows the specified fields for each order.

Adding Filters for Date Filtering

This section covers adding filters for date filtering in the admin panel.

Adding List Filter

  • To add a filter for date filtering, list_filter is used.
  • The field to filter by (in this case, "fecha") is specified within list_filter.

Saving Changes and Testing Filter

  • After saving changes, the admin panel now includes a filter option for dates.
  • Users can filter orders based on specific days or time periods (e.g., today, past seven days).

Using Breadcrumb Filters for Precise Date Filtering

This section explains how to use breadcrumb filters for precise date filtering.

Adding Breadcrumb Filter

  • To add a breadcrumb filter, the date_hierarchy attribute is used.
  • The desired field to filter by (in this case, "fecha") is specified within date_hierarchy.

Saving Changes and Testing Breadcrumb Filter

  • After saving changes, the admin panel now includes a breadcrumb filter that allows users to navigate through different months and days.
  • Users can easily filter orders based on specific dates or time periods.

Changing the Language of the Admin Panel

This section demonstrates how to change the language of the admin panel.

Importance of English in Programming

  • The speaker emphasizes the importance of knowing English in programming due to the abundance of resources available in English.

Translating Admin Panel into Spanish

  • Although working with English is recommended, it's possible to translate the admin panel into Spanish.

Changing the Language Settings

In this section, the speaker explains how to change the language settings in a specific file.

How to Change the Language Settings

  • To change the language settings, go to the "settings" file.
  • Locate the "team spirit" section within the settings file.
  • Search for the instruction "language code" within that section.
  • By default, it is set to American English. If you want to keep this instruction, you can comment it out and add a new line below.

Example of Changing Language to Spanish

The speaker demonstrates changing the language setting from English to Spanish.

Steps for Changing Language to Spanish

  • Copy and paste the original instruction before making changes.
  • Replace "English" with "Spanish".
  • Save the changes.

Updating and Viewing Changes

After changing the language settings, this section shows how to update and view the changes made.

Updating and Viewing Changes

  • Go to the administration panel.
  • Update or refresh the page for automatic changes to take effect.
  • All menus and filters will now be displayed in Spanish.

New Year's Message and Plans for 2020

The speaker shares a New Year's message and discusses plans for their channel and online platform in 2020.

New Year's Message and Plans

  • Expresses gratitude towards followers for their support throughout the year.
  • Wishes everyone a happy new year .
  • Announces upcoming plans for their channel and online platform:
  • Introducing new programming languages as requested by viewers.
  • Restructuring work schedule to dedicate more time to YouTube channel and online platform.

Invitation to Join Online Academy

The speaker invites viewers to join their online academy and highlights the availability of free courses.

Invitation to Join Online Academy

  • Encourages viewers to register for free on their virtual academy website.
  • Mentions the "free courses" section, where all YouTube courses are organized by categories.

Turn any video into a summary like this

YouTube links, meetings, lectures. With transcripts, search, and chat.

Playlists: Curso Django
Video description

Seguimos trabajando en el Panel de Adminsitración de Django, en esta ocasión agregando filtros para buscar registros en tablas y viendo cómo cambiar el idioma del panel de administración (al español). FELIZ AÑO A TODOS!! Para más cursos, ejercicios y manuales visita: www.pildorasinformaticas.es