diff --git a/invitations/views.py b/invitations/views.py index f98735f..9a6020a 100644 --- a/invitations/views.py +++ b/invitations/views.py @@ -71,6 +71,15 @@ def post(self, request, *args, **kwargs): try: validate_email(invitee) CleanEmailMixin().validate_invitation(invitee) + # ^as a read-only check it does not change old entries as needed: + invalid_invitations = Invitation.objects.all().exclude( + pk__in=Invitation.objects.all_valid() + ) + target_invitation = invalid_invitations.filter( + email__iexact=invitee + ) + if target_invitation: + target_invitation.get().delete() # email is unique, .get works invite = Invitation.create(invitee) except (ValueError, KeyError): pass