Only one registration for you

This commit is contained in:
Midgard 2020-07-22 16:16:33 +02:00
parent 4a80c56e85
commit e685a35d19
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -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}]"