对象名称未显示在管理中
Object Names not displaying in Admin
任何人都可以帮我解决为什么类别名称没有显示在我的管理控制台中的问题吗?我正在尝试使用 smart_selects 但似乎某些设置不正确。我正在使用 django 1.9,python 2.7
这是我的 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)
这是我的 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)
我在设置中注册了应用程序
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'smart_selects',
'app',
'blog',
]
但这是它在管理控制台中的样子
你的函数名是错误的。 __unicode__
有 2 个下划线,没有一个。
任何人都可以帮我解决为什么类别名称没有显示在我的管理控制台中的问题吗?我正在尝试使用 smart_selects 但似乎某些设置不正确。我正在使用 django 1.9,python 2.7
这是我的 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)
这是我的 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)
我在设置中注册了应用程序
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'smart_selects',
'app',
'blog',
]
但这是它在管理控制台中的样子
你的函数名是错误的。 __unicode__
有 2 个下划线,没有一个。