在Django 1.1管理员,当我去添加或更改一个对象,我的对象将显示为:
Select host to change
* Add host
Host object
Host object
Host object
Host object
Host object
这发生在我的网站上的所有车型,而不仅仅是主机。
而不是为每个对象显示相同的名字,我想Django的显示的主键。
Select host to change
* Add host
machine1
machine2
这里是我的代码:
from django.db import models
# Create your models here.
class Host(models.Model):
host = models.CharField(max_length=100,primary_key=True)
class Admin:
list_display = ('host')
class Test(models.Model):
testname = models.CharField(max_length=100,primary_key=True)
class Admin:
list_display = ('testname')
class Result(models.Model):
host = models.ForeignKey(Host)
TESTRESULT_CHOICES = (
('P', 'Pass'),
('F', 'Fail'),
)
testresult = models.CharField(max_length=1, choices=TESTRESULT_CHOICES)
reason = models.CharField(max_length=100)
time = models.DateTimeField()
testname = models.OneToOneField(Test, primary_key=True)
class Admin:
list_display = ('host','testname','time','testresult','reason')
阅读http://docs.djangoproject.com/en/dev/ref/contrib/admin/ :
“ModelAdmin.list_display
设置list_display来控制哪些字段显示在管理员的列表页面上“。
然而,这只是似乎并没有工作。 难道我做错了什么?