允许组创建者/所有者批准/拒绝用户加入组的请求

时间:2012-10-05 06:30:16

标签: django django-models django-users

我希望Users能够请求加入Group,创建该群组的人将被称为Owner,而任何非Owner将会要求加入Owner的小组。 Owner可以批准或拒绝用户的请求。 Owner也可以将用户添加到GroupUser可以批准/拒绝Owner的请求。有关如何入门的任何建议?

1 个答案:

答案 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)