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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -