不,你不能那样做。为多个类存储同一张表并不是那么简单。
您需要的可能是djeneralize项目。
从例子:
class Fruit(BaseGeneralizedModel):
name = models.CharField(max_length=30)
def __unicode__(self):
return self.name
class Apple(Fruit):
radius = models.IntegerField()
class Meta:
specialization = 'apple'
class Banana(Fruit):
curvature = models.DecimalField(max_digits=3, decimal_places=2)
class Meta:
specialization = 'banana'
class Clementine(Fruit):
pips = models.BooleanField(default=True)
class Meta:
specialization = 'clementine'
which then allows the following queries to be executed:
>>> Fruit.objects.all() # what we've got at the moment
[<Fruit: Rosy apple>, <Fruit: Bendy banana>, <Fruit: Sweet
clementine>]
>>> Fruit.specializations.all() # the new stuff!
[<Apple: Rosy apple>, <Banana: Bendy banana>, <Clementine: Sweet
clementine>]