I have defined some models which look like this:
class ABClass(models.Model):
#common attributes
class Meta:
abstract = True
class ConcreteClass1(ABClass):
#implementation specific attributes
class ConcreteClass2(ABClass):
#implementation specific attributes
class ModifiedConcreteClass1(ConcreteClass1):
#implementation specific attributes
I have a view which takes a 'type' parameter which specifies the type of class to display. If 'type=None' I want to display all descendents of ABClass (in this case, ConcreteClass{1,2}, ModifiedConcreteClass1). I have poked around the documentation and cannot seem to find a way of doing this which does not require list of ConcreteClasses be maintained. ABClass.__subclasses__()
seemed promising but it returns an empty list when I call it.
At present the best strategy I have is to create a CLASS_LIST variable in models.py which is populated with all descendents of ABClass at runtime using inspect
methods. Is there a way to do this using the django api?
Thanks