Skip to content

Commit

Permalink
Catch reuse of cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
bullestock committed Oct 5, 2024
1 parent 0d34796 commit 4f8508b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/members/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ class Member(AbstractUser):

def __str__(self):
return self.get_full_name()

@receiver(pre_save)
def pre_save_handler(sender, instance, *args, **kwargs):
if instance.card_id is not None:
users = Member.objects.filter(card_id=instance.card_id)
for user in users:
if user.id != instance.id:
raise Exception(f'User "{user.first_name} {user.last_name}" already has card ID {instance.card_id}')

0 comments on commit 4f8508b

Please sign in to comment.