我希望Users
能够请求加入Group
,创建该群组的人将被称为Owner
,而任何非Owner
将会要求加入Owner
的小组。 Owner
可以批准或拒绝用户的请求。 Owner
也可以将用户添加到Group
,User
可以批准/拒绝Owner
的请求。有关如何入门的任何建议?
答案 0 :(得分:2)
我有一个具有相同要求的django应用程序。以下是我对其进行建模的方式(当然没有“正确”的方式,这取决于您的应用程序的需求):
class User(models.Model):
number = models.CharField(max_length=24)
name = models.CharField(max_length=128, blank=True, null=True)
email = models.CharField(max_length=64, blank=True, null=True)
...
class Group(models.Model):
name = models.CharField(max_length=128)
owner = models.ForeignKey(User)
members = models.ManyToManyField(User, through='Membership', related_name='members', blank=True, null=True)
...
class Membership(models.Model):
# You can add other statuses depending on your application's needs
STATUS_SUBSCRIBED = 0
STATUS_UNSUBSCRIBED = 1
STATUS_REQUESTED = 2
STATUS = (
(STATUS_SUBSCRIBED, 'Joined'),
(STATUS_UNSUBSCRIBED, 'Unsubscribed'),
(STATUS_REQUESTED, 'Requested'),
)
user = models.ForeignKey(User)
group = models.ForeignKey(Group)
status = models.IntegerField(choices=STATUS)
added = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)