在Django的orm中,若是有多對多的字段,那麼他的第三張表時本身生成的,參考官方文檔發現第三張表能夠本身寫↓:django
並且第三張表好像是能夠自定製的spa
from django.db import models class Person(models.Model): name = models.CharField(max_length=128) def __str__(self): return self.name class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Membership') # Membership是第三張表的表名 def __str__(self): return self.name class Membership(models.Model): person = models.ForeignKey(Person, on_delete=models.CASCADE) # 創建外鍵關聯 group = models.ForeignKey(Group, on_delete=models.CASCADE) date_joined = models.DateField() # 新增擴展字段 invite_reason = models.CharField(max_length=64)