I have a class like this:
class ControlVocabulary(models.Model):
definition = models.TextField()
term = models.CharField(primary_key=True, max_length=255)
class Meta:
abstract = True
Why can't I use 'definition' inside of a child class? Is there a way that I can do this?
class ActionType(ControlVocabulary):
definition = ControlVocabulary.definition # <-- Error
class Meta:
#...
UPDATE: It looks like this is not permitted in Django, but I am still searching for a work-around to this problem. In Django - Model Inheritance - Does it allow you to override a parent model's attribute?
My view class:
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
Part of vocabularies dictionary:
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',
},