8

Can I show a grouped result in Django Admin? By default, they are showing all rows, I want to group these rows based on some fields, and display it.

Something like "GROUP BY username" or stuff. I've tried to search but no luck :(

djangouser
  • 111
  • 1
  • 4

2 Answers2

0

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

Lapin-Blanc
  • 1,945
  • 1
  • 17
  • 26
  • [list_filters](http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter) add filters and does not change ordering – dting Apr 18 '11 at 06:22
  • 1
    I don't think he wants to order, he speaks about grouping / filtering the results. I hope I get it right :-) – Lapin-Blanc Apr 18 '11 at 06:28
  • Hmm, after rereading the initial question. you might be right. =) – dting Apr 18 '11 at 06:33
-3

Yes, you can.

this applies to the detail view of the records. Here is an example listed 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.

ApPeL
  • 4,801
  • 9
  • 47
  • 84
  • 1
    This would be a good answer if it was about grouping form fields, but it is abot grouping list rows. – Steve K Oct 17 '12 at 13:01