python - Django: Check if a object exists but isn't current instance of object -
i've set basic cms scheme project , i'm adding order scheme can order created pages in nav bar. unfortunately custom validator i've written little aggressive , raises , error when edit page because, correctly, order exists in database.
model form based on:
class page(models.model): page_name = models.charfield(max_length=100) page_content = models.charfield(max_length=16777000) link = models.urlfield(blank=true) order = models.integerfield()
custom validator:
def clean_order(self): info = self.cleaned_data['order'] pg = page.objects.filter(order=data) if pg.count() > 0: raise forms.validationerror("this order number exists. utilize another.") homecoming info
is there way me to, upon performing update, have custom validator raise error if new order exists not current page object. like:
pg = page.objects.filter(order=data).filter(pk!=editpagepk)
thanks!
use exclude method, so:
pg = page.objects.filter(order=data).exclude(pk=self.instance.pk)
python django django-validation
No comments:
Post a Comment