Hi Roman,
you can use model validation
https://docs.djangoproject.com/en/dev/ref/models/instances/#validating-objects

It works similar to form validation. After, when you create ModelForm,
it will take validation rules from model.

All these validations should be called outside save()


Cheers,
  Tom

Dne Wed, 3 Jul 2013 10:21:51 +0200
Roman Klesel <roman.kle...@gmail.com> napsal(a):

> Hello,
> 
> I'm programming a database front end. In many cases I want to
> constrain the data written to the database. Therefore I implement some
> checks either through real database constraints or trough some logic
> in the model, so it will throw an exception when the constraints are
> not met.
> 
> e.g.: unique constraint on a database column.
> 
> Now, when I write my form validation, I have to implement the same
> logic again, since form validation takes place before a save() is even
> considered. Like this:
> 
> >>> if form.is_valid():
> >>>    form.save()
> 
> Is there a better way to do it? Is there a good way to avoid this
> duplicate logic?
> 
> Regards
>   Roman
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to