python - django objects.filter exclude yourself -
handling uniqueness in code in django, i've found problem: how check records @ validators, excluding yourself, because update function?
i've trying below, doesn't works.
please, me?
model.py
def check_email_person(email_given): myid = person.id if person.objects.filter(email=email_given).exclude(id__in=myid): raise validationerror(u"e-mail exists!") class person(models.model): email = models.emailfield(blank=true, null=true, validators=[check_email_person])
you should in form validation:
def clean_email(self): email = self.cleaned_data["email"] try: user.objects.get(email=email) except user.doesnotexist: return email raise forms.validationerror('duplicate_email')
Comments
Post a Comment