See #248: can now filter on invitation status and delete invitations

This commit is contained in:
Eliot Berriot 2018-06-21 19:22:51 +02:00
parent 7b0148a533
commit 7cfa61292a
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
8 changed files with 67 additions and 20 deletions

View file

@ -157,12 +157,13 @@ def generate_code(length=10):
class InvitationQuerySet(models.QuerySet):
def open(self):
def open(self, include=True):
now = timezone.now()
qs = self.annotate(_users=models.Count("users"))
qs = qs.filter(_users=0)
qs = qs.exclude(expiration_date__lte=now)
return qs
query = models.Q(_users=0, expiration_date__gt=now)
if include:
return qs.filter(query)
return qs.exclude(query)
class Invitation(models.Model):