Created
January 30, 2022 16:58
-
-
Save lu911/6cc9506bafc4a33dd17206a414a39234 to your computer and use it in GitHub Desktop.
Django M2M
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.db import models | |
class Person(models.Model): | |
name = models.CharField(max_length=128) | |
class Group(models.Model): | |
name = models.CharField(max_length=128) | |
members = models.ManyToManyField(Person, through='Membership') | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment