Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

django admin list_display not a callable

class branch(models.Model):
    name = models.CharField(max_length=10, unique=True)

class company_group(models.Model):          
    branch = models.ForeignKey(branch, on_delete=CASCADE)     
    segment = models.ForeignKey(segment, on_delete=CASCADE)

class position_control(models.Model):    
    company_group = models.ForeignKey(company_group, on_delete=CASCADE) 
    position = models.ForeignKey(position, on_delete=CASCADE) 
    rank = models.SmallIntegerField()    
    valid = models.BooleanField(default=True)

class PositionControlAdmin(admin.ModelAdmin):
    list_display = ('company_group__branch', 'position', 'rank', 'valid')
    list_filter = ('company_group__branch',)

I got error <class ‘information.admin.PositionControlAdmin’>: (admin.E108) The value of ‘list_display[0]’ refers to ‘company_group__branch’, which is not a callable, an attribute of ‘PositionControlAdmin’, or an attribute or method on ‘information.position_control’.

With list_filter company_group__branch is working fine. But got error in list_display. How can I fix that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

For the list display, you work with a function, not with a chain of underscore separated field names, so:

class PositionControlAdmin(admin.ModelAdmin):
    list_display = ('branch_name', 'position', 'rank', 'valid')
    list_filter = ('company_group__branch',)

    @admin.display(description='Branch name')
    def branch_name(self, object):
        return object.company_group.branch.name
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading