Greetings to all.
I am creating a model that I call Evento
, this is related to a model called PersonaNatural
by means of an intermediate table. AsistentesEvento
I need many people to attend an event and one person can go to many events but can only register once per event such like ManyToMany
Django's does. Below my code.
class Evento(RegistroTiempo):
# Campos del modelo
class PersonaNatural(RegistroTiempo):
# Campos del modelo
class AsistentesEvento(RegistroTiempo):
evento = models.ForeignKey(Evento, null=False, blank=False, verbose_name=_('evento'), on_delete=models.PROTECT)
invitado = models.ForeignKey(PersonaNatural, null=False, blank=False, verbose_name=_('invitado'),
on_delete=models.PROTECT)
asistio = models.BooleanField(default=False, null=True, blank=True, verbose_name=_('asistió'))
The point is that in this way a person can register several times as an attendee at an event. How can I limit this to one time per event?
If what you want is that a person can register only once in an event, you can use the UniqueConstraint class in the model
AsistentesEvento
, the code would look like this:In this way a person can only register once in an event