我有这样一节课:
class ControlVocabulary(models.Model):
definition = models.TextField()
term = models.CharField(primary_key=True, max_length=255)
class Meta:
abstract = True
为什么我不能在子类中使用“definition”?有没有办法让我这么做?你知道吗
class ActionType(ControlVocabulary):
definition = ControlVocabulary.definition # <-- Error
class Meta:
#...
更新: 看起来这在Django是不允许的,但是我仍然在寻找解决这个问题的方法。In Django - Model Inheritance - Does it allow you to override a parent model's attribute?
我的视图类:
class VocabulariesView(ListView):
queryset = []
template_name = 'cvinterface/index.html'
def get_context_data(self, **kwargs):
context = super(VocabulariesView, self).get_context_data(**kwargs)
context['vocabulary_views'] = [{'name': vocabularies[vocabulary_name]['name'], 'definition': vocabularies[vocabulary_name]['definition'], 'url': reverse(vocabulary_name)}
for vocabulary_name in vocabularies]
return context
词汇词典的一部分:
vocabularies = {
# optional keys:
# list_view, detail_view, list_template, detail_template
'actiontype': {
'name': ActionType._meta.verbose_name,
'definition': ActionType._meta.definition,
'model': ActionType,
'detail_template': 'cvinterface/vocabularies/actiontype_detail.html',
},
您不必在
ActionType
中定义definition
,因为它已经从ControlVocabulary
继承了您可以按如下方式进行检查:
另一种检查方法是查看数据库中模型的字段
编辑:
尝试复制错误:
型号:
在贝壳里:
相关问题 更多 >
编程相关推荐