Only one registration for you
This commit is contained in:
parent
4a80c56e85
commit
e685a35d19
1 changed files with 9 additions and 0 deletions
|
@ -46,6 +46,15 @@ class EventRegistration(models.Model):
|
||||||
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
|
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
|
||||||
state = models.CharField(max_length=1, choices=REGISTRATION_STATE.items())
|
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):
|
def __str__(self):
|
||||||
return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]"
|
return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue