Django admin: grouped data in a list

Is it possible to show a grouped result in Django Admin? By default, they show all lines, I want to group these lines based on some fields and display them.

Something like "GROUP BY username" or something. I tried to search, but no luck :(

+6
source share
2 answers

How about using list_filter='my_field' in the admin.py file?

0
source

Yes, you can.

this refers to a detailed view of records. Below is an example below.

 class GroupAdmin(admin.ModelAdmin): form = SpecieForm list_display = ('species', 'latin_name', 'family', 'status') search_fields = ['species', 'latin_name'] prepopulated_fields = { 'slug': ['species'] } fieldsets = [ (None, {'fields': ['field1', 'field2', 'field3', 'field4']}), ('Image', {'fields': ['original_image']}), ('Other Group', {'fields': ['other_field1', 'other_field2', 'other_field3', 'other_field4']}), ] admin.site.register(Group, GroupAdmin) 

Hope this helps.

-2
source

Source: https://habr.com/ru/post/886115/


All Articles