Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model field not displaying in Django Admin

I have a Django project hosted on heroku

I added a new slug field to model

from django.db import models

class Category(models.Model):
    name = models.CharField(max_length=30)
    slug = models.SlugField(unique=True)

    def __unicode__(self):
        return self.name

migrated it using south on heroku. Checked the heroku postgresDB as well for added field. All fine.

Opened Admin. No slug field showing...

added slug to fields[] in admin.py. Still not showing. Here is admin.py

from django.contrib import admin
from models import Category

class CategoryAdmin(admin.ModelAdmin):
    fields    = ('name', 'slug')

admin.site.register(Category, CategoryAdmin).

I even did a heroku restart... No change. What can be done to show it ?

like image 543
zephyr Avatar asked Feb 16 '23 11:02

zephyr


1 Answers

Try to use list_display like following:

from django.contrib import admin
from models import Category

class CategoryAdmin(admin.ModelAdmin):
    fields    = ('name', 'slug')

    #list of fields to display in django admin
    list_display = ['id', 'name', 'slug']


    #if you want django admin to show the search bar, just add this line
    search_fields = ['name', 'slug']

    #to define model data list ordering
    ordering = ('id','name')

admin.site.register(Category, CategoryAdmin).
like image 67
Boston Kenne Avatar answered Feb 24 '23 11:02

Boston Kenne