2

When I am trying to save not unique object I am getting this error:

UNIQUE constraint failed: event_invitedperson.email, event_invitedperson.event_id

Where and how should I check if record is unique before saving?

My model:

class InvitedPerson(models.Model): email = models.EmailField("") event = models.ForeignKey(Event) class Meta: unique_together = [('email', 'event')] 

model:

class InvitedPerson(models.Model): email = models.EmailField("") event = models.ManyToManyField(Event) 
0

1 Answer 1

1

Why not use get_or_create method.

>>> InvitedPerson.objects.get_or_create(email='[email protected]', event=event1) (<InvitedPerson: InvitedPerson object>, True) >>> InvitedPerson.objects.get_or_create(email='[email protected]', event=event2) (<InvitedPerson: InvitedPerson object>, True) 

So email will associated with multiple event...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.