views:

20

answers:

1

Hi all,

I have a class Task(models.Model), and i didn't define id field explicitly (since it defines automatically for you). I checked in the database, it exists for the Task. Now i would like to display it in the list via list_display property in admin.ModelAdmin. I have a bunch of things in there, only id is not showing up for any of the rows i have. Everything else works fine. Anyone know anything special i have to do to get id to display?

EDIT: if i define a function as follows:

def ID(self, obj):
        return obj.id

and i put this function in list_display, it will display id just fine for some reason.

Thanks a lot!

Jason

A: 

It doesn't show by default. You need to create a custom Admin class for that model and then add 'id' to the list_display value. E.g. in whatever/admin.py:

class TaskAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', etc. etc] 

admin.site.register(Task, TaskAdmin)

See the docs for more details.

Peter Rowell
Hi Peter, thanks a lot for your response! However, i did put it in the list_display, and it doesn't show up. However, if i put 'ID' per the function definition, it does show up. I'm not sure what the problem is.
FurtiveFelon
Hmmm ... I would need to see the code for the models.Model class and the admin.ModelAdmin class to give you anymore help. Remember, case *is* significant here, so that might be a contributing factor.
Peter Rowell