Bayko
Bayko

Reputation: 1434

Django: list_display is not callable

I have a few models: ModelA, ModelB, ModelC each with identical attributes say x,y,z. I am trying to get them displayed in Django admin. I have registered each as

@admin.register(ModelA)
class ModelAAdmin(admin.ModelAdmin):
    list_display = ['x', 'y' , 'z']

However when I runserver, I get error which says

The value of list_display[0] refers to 'x' which is not callable, an attribute of modelA, or an attribute or method on 'database.modelA'

I am guessing this has got something to do with each model having identical names but I am not sure. How do I resolve this?

EDIT- the models are pretty basic with

class ModelA(models.Model):
    x = models.CharField(max_length = 30)
    y = models.CharField(max_length = 30)
    z = models.CharField(max_length = 30)

Upvotes: 3

Views: 3395

Answers (2)

Marvin Villaver
Marvin Villaver

Reputation: 11

list_display = ['x', 'y' , 'z']

Change to:

list_display = ['x', 'y' , 'z',]

Note: always put a "," after the last fields that you want to display

Upvotes: 0

Druta Ruslan
Druta Ruslan

Reputation: 7412

Set list_display to control which fields are displayed on the change list page of the admin. Example:

list_display = ('first_name', 'last_name')

docs

Edit can you try this?

class ModelAAdmin(admin.ModelAdmin):
    model = ModelA
    list_display = ['x', 'y' , 'z',] # important there is a comma after 'z',

admin.site.register(ModelA, ModalAAdmin)

Upvotes: 2

Related Questions