我有以下django模型:
SALAMI_TYPES = (
('S', 'Spicy'),
('R', 'Regular')
)
CHEESES = (
('P', 'Parmesan'),
('C', 'Cheddar')
)
class Pizza(models.Model):
size = models.IntegerField()
class Meta:
abstract = True
class Pepperoni(Pizza):
salami = models.CharField(max_length=1, choices=SALAMI_TYPES)
class ExtraCheese(Pizza):
cheese = models.CharField(max_length=1, choices=CHEESES)
以下问题:
感谢。
答案 0 :(得分:2)
您可以通过询问python类层次结构来完成此操作:
How can I find all subclasses of a class given its name?
在您的情况下,您希望获得' Pizza'的所有子类,如下所示:
Pizza.__subclasses__()