标签:person key reason 自定义 asc 字段 man tom rom
from django.db import models
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, on_delete=models.CASCADE)
person = models.ForeignKey(Person, on_delete=models.CASCADE)
inviter = models.ForeignKey(
Person,
on_delete=models.CASCADE,
related_name="membership_invites",
)
invite_reason = models.CharField(max_length=64)
through_fields=(‘group‘, ‘person‘), 通过后端返回的是Membership 注意
(‘group‘, ‘person‘) 第一个字段指向自己。第二字段指向别人
标签:person key reason 自定义 asc 字段 man tom rom
原文地址:http://www.cnblogs.com/tiantao36/p/7574724.html