0

I want to have the ability for Users to request to join a Group the person who created the group would be called Owner and any non-Owner would have to request to join Owner's group. The Owner can approve or deny the request from the user. The Owner could also add users to their Group and the User could approve/deny the Owner's request. Any suggestions on how to get started?

jmitchel3
  • 391
  • 3
  • 4
  • 17

1 Answers1

2

I have a django app with identical requirements. Here's how I modeled it (of course there is no "right" way, it depends on your application's needs):

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)
Neil
  • 7,042
  • 9
  • 43
  • 78
  • So from a view, how would you allow the Group owner (`request.user`) to change the `members`s request status? – jmitchel3 Oct 05 '12 at 07:31