django 管理应用程序错误(带有属性字段的模型):全局名称“full_name”没有定义
这是我的模型:
class Author(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
middle_name = models.CharField(max_length=200, blank=True)
def __unicode__(self):
return full_name
def _get_full_name(self):
"Returns the person's full name."
if self.middle_name == '':
return "%s %s" % (self.first_name, self.last_name)
else:
return "%s %s %s" % (self.first_name, self.middle_name, self.last_name)
full_name = property(_get_full_name)
一切都很好,除了当我进入管理界面时,我
在 /bibbase2/admin/bibbase2/author/ 看到 TemplateSyntaxError 渲染时捕获异常:未定义全局名称“full_name”
似乎内置管理应用程序不适用于属性字段。我的代码有问题吗?
This is my model:
class Author(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
middle_name = models.CharField(max_length=200, blank=True)
def __unicode__(self):
return full_name
def _get_full_name(self):
"Returns the person's full name."
if self.middle_name == '':
return "%s %s" % (self.first_name, self.last_name)
else:
return "%s %s %s" % (self.first_name, self.middle_name, self.last_name)
full_name = property(_get_full_name)
Everything is fine except when I go into admin interface, I see
TemplateSyntaxError at /bibbase2/admin/bibbase2/author/
Caught an exception while rendering: global name 'full_name' is not defined
It seems like the built-in admin app doesn't work with a property field. Is there something wrong with my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是:
Should be: