Reputation: 391
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?
Upvotes: 0
Views: 262
Reputation: 7202
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)
Upvotes: 2