diff --git a/events/models.py b/events/models.py index 754ebd8..dabbbfc 100644 --- a/events/models.py +++ b/events/models.py @@ -46,6 +46,15 @@ class EventRegistration(models.Model): user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) state = models.CharField(max_length=1, choices=REGISTRATION_STATE.items()) + + class Meta: + constraints = [ + models.UniqueConstraint( + fields=["event", "user"], name="user can only register once per event" + ) + ] + + def __str__(self): return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]"