我有以下对象结构:
class Car(models.Model):
name = models.CharField(max_length=16)
class Person(models.Model):
name = models.CharField(max_length=32)
cars = models.ManyToManyField(Car, through='Relationship')
parent = models.ForeignKey('self', null=True, blank=True, related_name='childrens')
class Relationship(models.Model):
car = models.ForeignKey(Car)
person = models.ForeignKey(Person)
love = models.BooleanField(_('love status'), default=True, db_index=True)
模型的逻辑是:
此逻辑看起来像继承。我无法通过Multi-table inheritance实现此逻辑,因为孩子可能还有其他孩子。也许有一些想法,如多记录继承?