Python Django Tutorial: Advanced Admin Interface - Part Six

Today, I will share one new part of Python Django from my tutorial series. In this part you will learn the Advanced admin interface in django.

I already told you the following:

Django provides many features to use in admin panel of django.I have already told you some basics of django admin in my previous article. So you can use the previous article model's structure and can also create new models fo it in this advanced  admin interface.

  1. According to the previous article fill up the information of publisher model's data and save it.



  2. After saving you will interface of publisher as below image.



  3. In above image you will see publisher object. Not user information here. When you click this object you will get automatic fill up form with information. But my main concern is fetching object name rather than publisher object.

  4. So now we go to models.py file and write a predefine method in models call of publisher.



  5. Here a method def __str__(self) is used for return data when we want to access this model. When we see this model in admin panel, it will always show name of publisher rather than publisher object. Now go to Admin panel and refresh page of publisher.



  6. So this depends on return of __str__ method. We can also return anything that will always show here above image. See another demo.



  7. Here str method returns all table attribute values. So now check in admin interface.



  8. It works. Here you see title of publisher is single which holds all values. Now another feature is django shows all values with different-2 column. Now change the models.py str method that will return only name of Publisher.

  9. Now we go to admin.py file and write some as below image.



  10. Above code represents the class which has list_display variable this is predefined in django and adds attributes of django models in it according to your choices. Now we check admin panel .



  11. You can see all data in different-2 columns.

  12. We can add searching in admin model for search data when you have many data in that model.

  13. Now we go to admin.py file and write code as below.



  14. Here name, city and country is that field that can help for search data into admin interface.



  15. This is the searching in django admin interface. Now we move another feature of djnago that is filter of data.

  16. Add code in admin.py



  17. Check in admin Interface.


  18. It works. Django admin also has some other features:

    • date_hierarchy
    • ordering
    • filter_horizontal
    • raw_id_fields

  19. Now we simply see above all feature demos in a single example.



So this is the Advanced use of admin interface. Django Provides best admin framework feature and also we can customize admin using user defined  methods.

Up Next
    Ebook Download
    View all
    Learn
    View all