【发布时间】:2013-11-10 20:40:31
【问题描述】:
我在 Django 中使用 mongoengine。我有一个类 Noun,其他几个类(Person、Place、Event 等)从该类继承。 Noun 类如下所示:
class Noun(Document):
label = StringField(max_length=120, required=True)
contributor = StringField(max_length=120, required=True)
description = StringField(required=False)
@property
def noun_cls():
return self._cls
meta = {'allow_inheritance': True}
当我尝试在模板中引用 noun_cls 属性时,我什么也得不到。例如:
{% for noun in Nouns %}
<li>
<a href="{{BASE_URL}}noun/update/{{ noun.id }}/{{ noun.noun_cls }}/">Edit {{ noun.noun_cls }}</a>
<p>{{ noun.description }}</p>
</li>
{% endfor %}
...这会产生类似“...noun/update/[long mongo id]//”的 url。就好像 noun_cls 属性被完全忽略了。对于先前存在的名词(或任何类型)以及在此代码更改后生成的新名词都是如此。有什么想法吗?
【问题讨论】:
-
属性应该可以正常工作 - 只是没有
_cls值。
标签: django mongodb django-models mongoengine