Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:13:33+00:00 2026-05-27T22:13:33+00:00

I need group columns in django admin for given db table. I will take

  • 0

I need group columns in django admin for given db table. I will take sample table ‘Student’ which has columns id, first_name, last_name, address1, address2, address3. So grouping will be like this:

ID -> id

NAME -> first_name, last_name

ADDRESS -> address1, address2, address3

The purpose of this to get label for set of columns when I view rows of data from a table. So When I check for the rows fetched for Student table in Django’s admin section I should see something like this:

---------------------------------------------------------------------------------
| ID   | NAME                   | ADDRESS                                       |
---------------------------------------------------------------------------------
| ID   | First Name | Last Name | Address 1       | Address 2       | Address 3 |
---------------------------------------------------------------------------------
| 1    | Ron        | DCunha    | 1st Cross       | Valencia        | Mangalore |
--------------------------------------------------------------------------------|
| 2    | Akash      | Attavar   | Mark Street     | Attavar         | Mangalore |
---------------------------------------------------------------------------------

I must be able achieve this in admins.py (by writing a class that extends admin.ModelAdmin).Using list_display tuple I can list out the columns that I want to see. But I do not know how to group columns. Please help me out …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:13:34+00:00Added an answer on May 27, 2026 at 10:13 pm

    To do this, you simply create a method on your Model or ModelAdmin that returns the appropriate display you want, and then use that method name in your list_display (it takes field names or callables).

    class MyModelAdmin(admin.ModelAdmin):
        ...
        list_display = ('id', 'full_name')
    
        ...
    
        def full_name(self, obj):
            return u'%s %s' % (obj.first_name, obj.last_name)
    

    OR in your Model (better if the display is useful in other scenarios than the admin, otherwise use ModelAdmin):

    class MyModel(models.Model):
        ...
        def get_full_name(self):
            return u'%s %s' % (self.first_name, self.last_name)
    
    class MyModelAdmin(admin.ModelAdmin):
        ...
        list_display = ('id', 'get_full_name')
    

    If you want it to be orderable, you need to define admin_order_field on the method, but you’ll have to pick one field to use for the ordering:

    def full_name(self, obj):
        return u'%s %s' % (obj.first_name, obj.last_name)
    full_name.admin_order_field = 'last_name'
    

    If you need to include HTML, specify allow_tags=True on the method:

    def full_name(self, obj):
        return u'%s %s' % (obj.first_name, obj.last_name)
    full_name.allow_tags = True
    

    Finally, Django will compose the label automatically from the method name; in this case, it would end up being “Full name”. If you want something different you can use short_description:

    def full_name(self, obj):
        return u'%s %s' % (obj.first_name, obj.last_name)
    full_name.short_description = "User's Full Name"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a table that has the columns: 'product_id', 'price', ... (and others). I need
i need to drop columns which has value '0' in both the rows select
Given the XML below, I need to group by InputItem and sum the costs
I need to write a query that will group a large number of records
I need add a new user group for mediawiki. The new group has more
I have a table that has three columns: myColumn, myColumn2 and myColumn3. The three
I need an aggregate sum for a table column (grouped by other columns), but
I have table tblEvents with columns dEvent_Date, dEvent_Time, tEvent_Emp_Code_num I must group all dates
Here is a problem. I need to have 2 columns in a table both
i need a report and i should use pivot table for it.Report will be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.