0

我希望能够Users请求加入Group创建该组的人将被调用Owner,并且任何非Owner必须请求加入Owner的组。可以批准或拒绝用户的Owner请求。还可以将Owner用户添加到他们的Group并且User可以批准/拒绝Owner的请求。关于如何开始的任何建议?

4

1 回答 1

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)
于 2012-10-05T07:21:28.070 回答