1👍
✅
I don’t see any ManyToMany field in your models, but I think you’re looking for the through
options of ManyToManyField
. You can specify a custom table to use between your two related tables, and you can define its structure (fields):
An example here:
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=50)
class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(Person, through='Membership', through_fields=('group', 'person'))
class Membership(models.Model):
group = models.ForeignKey(Group)
person = models.ForeignKey(Person)
inviter = models.ForeignKey(Person, related_name="membership_invites")
invite_reason = models.CharField(max_length=64)
This was taken from Django ManyToMany Docs
Source:stackexchange.com