Thanks for answer. You have reason, I don't need do that. With a clean
method in the modelform is enough. This question appear, because
initialy I just wanted add a validator to the field of the model, but
for the validation the  parameter  "self" was necessary and I could
not find a way to pass this parameter. However I don't need this, with
a clean method in the form, I can solve this quickly.

On 9 nov, 13:44, cootetom <coote...@gmail.com> wrote:
> You say you want to do the clean in the model but then say you want
> the error to be associated with the field in the ModelForm? If you
> need that clean functionality to exist for both a model and a form of
> that model then you could shift the checks into a function of it's own
> out side of the class's then have a clean in both the model and the
> form which calls the function to do the checks before deciding how to
> raise the error.
>
> The issue is that a form and a model use validation errors in
> different ways. A form will send errors back to the templating layer
> to show to a user but a model doesn't work like that as it would only
> be manipulated directly in python code.
>
> Does that make sense?
>
> On Nov 9, 2:39 pm, refreegrata <refreegr...@yahoo.com> wrote:
>
> > ok, thanks for the answer, but I want use the clean method in a model,
> > not in a form. For that in the clean method I throw a ValidationError,
> > but the error message isn't associated to the field form of the
> > modelform.
>
> > On 8 nov, 19:17, cootetom <coote...@gmail.com> wrote:
>
> > > If you want to associate an error to a specific field in a model form
> > > then you need to populate self._errors with the error you find. Have a
> > > read about this on the Django docs to see how it is done.
>
> > >http://docs.djangoproject.com/en/1.1/ref/forms/validation/#ref-forms-...
>
> > > The last example shows how to associate a error with a specific field
> > > in a form class.
>
> > > On Nov 8, 8:40 pm, refreegrata <refreegr...@yahoo.com> wrote:
>
> > > > Hello list. I want to use the clean method in a model.
> > > > --------------------------------------
> > > > class myModel(models.Model):
> > > >     fields ....
>
> > > >     def clean(self):
> > > >             raise ValidationError('The Error.')
> > > > -------------------------------------------------------
>
> > > > Thats works fine. My question  is, how can I associate this error to
> > > > the field in the modelform?. With this method the form validation can
> > > > be controlled, but I can't pick the error dynamically to show at the
> > > > user.
>
> > > > Thanks for read.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to