KSHMR
KSHMR

Reputation: 809

Django -- list_display has no effect

This is my code:

from django.contrib import admin
from bjorncsv.models import *

class BondsAdmin(admin.ModelAdmin):
    list_display = ("rowid", "bond_id", "end_d", "intr", "base_i", "type", "start_d", "first_id", "first_pd")

admin.site.register(Bonds)

However, on the Admin interface, it's like the class isn't even there. This is the class in question:

class Bonds(models.Model):
    rowid = models.AutoField(primary_key=True)
    bond_id = models.TextField(blank=True)
    end_d = models.DateField(blank=True, null=True)
    intr = models.FloatField(blank=True, null=True)
    base_i = models.FloatField(blank=True, null=True)
    type = models.TextField(blank=True)
    start_d = models.DateField(blank=True, null=True)
    first_id = models.DateField(blank=True, null=True)
    first_pd = models.DateField(blank=True, null=True)
    class Meta:
        managed = True
        db_table = 'bonds'

Upvotes: 0

Views: 339

Answers (2)

pancakes
pancakes

Reputation: 712

You forgot to register Admin class ;-)

admin.site.register(Bonds, BondsAdmin)

Upvotes: 2

karthikr
karthikr

Reputation: 99620

You have to register it with your custom model admin

So, change:

admin.site.register(Bonds)

to

admin.site.register(Bonds, BondsAdmin)

If you do not specify the second parameter in the register call, the default admin interface will be provided, which of course does not have the list_display the way you want.

Documentation here

Upvotes: 2

Related Questions