如果我爲某個特定模型創建新條目,它不會顯示在django管理員中。Django Admin不顯示條目
代理模式造成了麻煩。
# catalog.models
class Content(models.Model):
class Meta:
abstract = True
BUNDESLAND_CHOICES = (
('bw', 'Baden-Württemberg'),
('by', 'Bayern'),
('be', 'Berlin'),
('bb', 'Brandenburg'),
('hb', 'Bremen'),
('hh', 'Hamburg'),
('he', 'Hessen'),
('mv', 'Mecklenburg-Vorpommern'),
('ni', 'Niedersachsen'),
('nw', 'Nordrhein-Westfalen'),
('rp', 'Rheinland-Pfalz'),
('sl', 'Saarland'),
('sn', 'Sachsen'),
('st', 'Sachsen-Anhalt'),
('sh', 'Schleswig-Holstein'),
('th', 'Thüringen'),
)
name = models.CharField(max_length=255, verbose_name='Agentur')
address = models.CharField(max_length=255, verbose_name='Straße')
state = models.CharField(max_length=2, choices=BUNDESLAND_CHOICES, verbose_name='Bundesland')
city = models.CharField(max_length=255, verbose_name='Stadt')
zip = models.CharField(max_length=10, verbose_name='PLZ')
phone = models.CharField(max_length=40, blank=True, verbose_name='Telefonnr.')
fax = models.CharField(max_length=40, blank=True, verbose_name='Fax')
email = models.EmailField(verbose_name='E-Mail', help_text='Offizielle E-Mail')
url = models.URLField(verbose_name='URL')
owner = models.CharField(max_length=255, verbose_name='Besitzer')
description = models.TextField(verbose_name='Beschreibung')
category = models.ManyToManyField(Category, verbose_name='Kategorie')
user = models.ForeignKey(User, verbose_name='Benutzer', null=True, blank=True)
slug = models.SlugField(max_length=80, blank=True)
identity = models.CharField(max_length=64, unique=True, blank=True)
identity_used = models.BooleanField(default=False)
show = models.BooleanField(default=False, verbose_name='Anzeigen')
tp = models.DateTimeField(auto_now_add=True)
# agency.models
class AgencyActiveManager(models.Manager):
def get_query_set(self):
return super(AgencyActiveManager,self).get_query_set().filter(show=True)
class Agency(Content):
clients = models.TextField(verbose_name='Klienten')
active = AgencyActiveManager()
objects = models.Manager()
def __unicode__(self):
return self.name
def save(self, **kwargs):
if not self.identity:
self.identity = hashlib.sha256('%s:%s' %(get_word(),datetime.datetime.now())).hexdigest()
if not self.slug:
self.slug = slugify(self.name, instance=self)
super(Agency, self).save(**kwargs)
# agency.admin
from django.contrib import admin
from agency.models import Agency
admin.site.register(Agency)
我在管理員中創建了一個新的代理商條目並保存了它。通過蟒蛇殼 查詢顯示,保存工作
In [15]: Agency.objects.all()
Out[15]: [<Agency: Argentur>]
管理頁面說: 「0中介機構的」
如果我嘗試手動調用URL /管理/代理商/代理/ 1 /我得到404說,有一個PrimaryKey的沒有機構對象沒有找到1
頁(404) 請求方法:GET 請求URL:http://localhost:8000/admin/agency/agency/1/
Das agency-Objekt mit demPrimärschlüsselu'1'ist nicht vorhanden。
你看到這個錯誤,因爲你的Django設置文件中有DEBUG = True。將其改爲False,Django將顯示一個標準的404頁面。
但蟒蛇殼說:
In [16]: Agency.objects.all()[0].pk
Out[16]: 1
我缺少的東西非常明顯?
我的猜測是它有一些與抽象模型相關的東西,但我無法弄清楚是什麼。