jazzband / django-invitations

Generic invitations app for Django
GNU General Public License v3.0
559 stars 166 forks source link

Proposal: add `invitee` field to AbstractBaseInvitation model #252

Open Flimm opened 2 months ago

Flimm commented 2 months ago

I would like to add this invitee field to AbstractBaseInvitation model:

class AbstractBaseInvitation(models.Model):
    invitee = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name=_("inviter"),
        null=True,
        blank=True,
        on_delete=models.CASCADE,
    )

This invitee field would be null initially. Once the invitee has created a new user account, after clicking the invitation link, the invitee field would set to the ID of the new user account.

I wanted to propose this to see what you would think, before attempting to implement it.

Motivation:

This library has been designed to keep Invitation instances in the database, even after the invitation has been accepted and the user account has been created. The only reason to keep these invitations around is to have a track record of invitations. It seems likely in that case that the inviter would want to be able to interact with the new user account, depending on the application. They may want to visit their profile page or something.

Right now, this is impossible to do, as there is nothing linking the invitation instance to a user instance. At first glance, it might seem that an email address would link both models, but that is not the case. A user is not obligated to sign up with the same email address that was used to invite them. Even if they do use the same email address, they may change their email address in their user account later on. So an email address cannot be relied on to link these two models.