2012-10-05 53 views
0

我希望有能力Users要求加入一個Group誰創建的組將被稱爲Owner任何非Owner將不得不請求的人加入Owner的小組。 Owner可以批准或拒絕來自用戶的請求。 Owner也可以將用戶添加到他們的Group,而User可以批准/拒絕Owner的請求。有關如何開始的任何建議?允許羣組創建者/所有者批准/拒絕用戶的請求加入羣

回答

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) 
+0

所以從視圖,你會如何讓本集團所有者('request.user')至改變'會員的請求狀態? – jmitchel3

+0

+1有幫助 - 謝謝 – tatlar