[Answer]-Model Inheritance with Django

1👍

You do not have to define the definition in your ActionType because it will be inherited already from your ControlVocabulary

You can check it already as follows:

x = ActionType.objects.all()
x[0].__dict__

Other way to check is by looking at the fields of you model in the database

EDIT:

Tried replicating the error:

models:

class ControlVocabulary(models.Model):
    definition = models.TextField()
    term = models.CharField(primary_key=True, max_length=255)
    class Meta:
        abstract = True
class ActionType(ControlVocabulary):
    #definition = ControlVocabulary.definition # <-- Error
    class Meta:
        verbose_name='Action'

and in the shell:

Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from testapp.models import *
>>> x = ActionType.objects.all()
>>> x
[]
>>> y = ActionType(definition='my definition')
>>> y.save()
>>> ActionType.objects.all()
[<ActionType: ActionType object>]

Leave a comment