我在覆盖包含在站点框架叉中的模型“站点”时遇到问题。我的站点上有一个带有“站点”的表单,我需要显示站点的名称,而不是 Site.domain,我覆盖模型,将其路由到“元”类中的同一个数据库表并得到错误,我不能明白了,代码在这里:
模型:
@python_2_unicode_compatible
class Site(models.Model):
domain = models.CharField(_('domain name'), max_length=100)
name = models.CharField(_('display name'), max_length=50)
objects = SiteManager()
class Meta:
db_table = 'django_site'
verbose_name = _('site')
verbose_name_plural = _('sites')
ordering = ('domain',)
def __str__(self):
return self.domain
def save(self, *args, **kwargs):
super(Site, self).save(*args, **kwargs)
# Cached information will likely be incorrect now.
if self.id in SITE_CACHE:
del SITE_CACHE[self.id]
def delete(self):
pk = self.pk
super(Site, self).delete()
try:
del SITE_CACHE[pk]
except KeyError:
pass
我的覆盖模型:
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
class NamedSite(Site):
def __str__(self):
return self.name
class Meta:
db_table = 'django_site'
verbose_name = _('site')
verbose_name_plural = _('sites')
ordering = ('domain',)
和错误
DatabaseError at <my url>
ERROR: Column django_site.site_ptr_id doesn't exist
LINE 1: ...ROM "django_site" INNER JOIN "django_site" T2 ON ("django_si...