mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 19:11:09 +00:00
Associate users with their invites
This commit is contained in:
parent
ec8eb01a0f
commit
634509a7f3
3 changed files with 23 additions and 0 deletions
21
bookwyrm/migrations/0060_siteinvite_invitees.py
Normal file
21
bookwyrm/migrations/0060_siteinvite_invitees.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.1.6 on 2021-04-02 00:14
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0059_user_preferred_timezone"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="siteinvite",
|
||||
name="invitees",
|
||||
field=models.ManyToManyField(
|
||||
related_name="invitees", to=settings.AUTH_USER_MODEL
|
||||
),
|
||||
),
|
||||
]
|
|
@ -58,6 +58,7 @@ class SiteInvite(models.Model):
|
|||
use_limit = models.IntegerField(blank=True, null=True)
|
||||
times_used = models.IntegerField(default=0)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
invitees = models.ManyToManyField(User, related_name="invitees")
|
||||
|
||||
def valid(self):
|
||||
""" make sure it hasn't expired or been used """
|
||||
|
|
|
@ -108,6 +108,7 @@ class Register(View):
|
|||
)
|
||||
if invite:
|
||||
invite.times_used += 1
|
||||
invite.invitees.add(user)
|
||||
invite.save()
|
||||
|
||||
login(request, user)
|
||||
|
|
Loading…
Reference in a new issue