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

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -