2

Can anyone help me fix why category names are not displaying in my admin console? I am trying to use smart_selects but it seems as though something is not setup correctly. I am using django 1.9, python 2.7

Here is my models.py

from __future__ import unicode_literals
from django.db import models
from smart_selects.db_fields import ChainedForeignKey

class Category (models.Model):
    category = models.CharField(max_length = 255)
    def _unicode_(self):
      return self.category


class Brand (models.Model):
    brand = models.ForeignKey(Category)
    def _unicode_(self):
      return self.brand


class Make (models.Model):
    category = models.ForeignKey(Category)
    brand = ChainedForeignKey(Brand, chained_field = 'category',
                              chained_model_field = 'category', show_all = False, auto_choose = True)

Here is my admin.py

from django.contrib import admin
from .models import Category, Brand, Make

admin.site.register(Category)
admin.site.register(Brand)
admin.site.register(Make)

I have the app registered in settings

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'smart_selects',
    'app',
    'blog',
]

But here is how it looks in Admin console Brand category object

enter image description here

4

1 回答 1

1

您的函数名称错误。它__unicode__有 2 个下划线而不是一个。

于 2016-03-11T19:56:47.763 回答