1. 自定义多对多中间表
class A(models.Model):
a_id = models.AutoField(primary_key=True)
a_name = models.CharField(max_length=255)
a_description = models.CharField(max_length=255)
class Meta:
managed = False
db_table = 'AAA'
class B(models.Model):
b_id = models.AutoField(primary_key=True)
b_name = models.CharField(max_length=255)
aa = models.ManyToManyField(A, through='Mdm', related_name='bb', through_fields=('b', 'a'))
class Meta:
managed = False
db_table = 'BBB'
class Mdm(models.Model):
id = models.AutoField(primary_key=True)
a = models.ForeignKey(A, db_constraint=False, on_delete=models.CASCADE)
b = models.ForeignKey(B, db_constraint=False, on_delete=models.CASCADE)
class Meta:
managed = False
db_table = 'MMM'