Re: ModelForm unbound

2011-04-21 Thread Constantine
Let me show example

on form i have two coerced fieds (ModelChoiceField)
queryset for second field based on first

so, using simpleform i can modify second queryset using
firstfield_clean
but using modelform i should do it twise:
in init for form instantiation and in field_clean for save
what about DRY?

> which presumably are already valid,
> otherwise they should not have been saved

db essentials could be invalid if there hard validation logic exists

On Apr 21, 7:35 pm, Daniel Roseman  wrote:
> On Thursday, April 21, 2011 8:16:36 AM UTC+1, Constantine wrote:
>
> > Hi
>
> > i've used some logic in clean_field methods, but when i've migrated to
> > ModelForm, was very surprised that clean methods does not invoked
> > after some investigation i realized that model instane does not makes
> > modelform bound automatically
>
> > i'm expect that model validation also triggered as pointed here
>
> >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-is-...
> > but models.py contradicts
> >     def is_valid(self):
> >         """
> >         Returns True if the form has no errors. Otherwise, False. If
> > errors are
> >         being ignored, returns False.
> >         """
> >         return self.is_bound and not bool(self.errors)
>
> > model with instance only WILL NOT trigger validation
>
> I'm not sure why that would surprise you, or why you would want it to work
> any other way. Form validation is for validating user input, not for
> checking already-saved instances (which presumably are already valid,
> otherwise they should not have been saved).
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Re: ModelForm unbound

2011-04-21 Thread Daniel Roseman


On Thursday, April 21, 2011 8:16:36 AM UTC+1, Constantine wrote:
>
> Hi 
>
> i've used some logic in clean_field methods, but when i've migrated to 
> ModelForm, was very surprised that clean methods does not invoked 
> after some investigation i realized that model instane does not makes 
> modelform bound automatically 
>
> i'm expect that model validation also triggered as pointed here 
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-is-valid-method-and-errors
>  
> but models.py contradicts 
> def is_valid(self): 
> """ 
> Returns True if the form has no errors. Otherwise, False. If 
> errors are 
> being ignored, returns False. 
> """ 
> return self.is_bound and not bool(self.errors) 
>
> model with instance only WILL NOT trigger validation 
>


I'm not sure why that would surprise you, or why you would want it to work 
any other way. Form validation is for validating user input, not for 
checking already-saved instances (which presumably are already valid, 
otherwise they should not have been saved).
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



ModelForm unbound

2011-04-21 Thread Constantine
Hi

i've used some logic in clean_field methods, but when i've migrated to
ModelForm, was very surprised that clean methods does not invoked
after some investigation i realized that model instane does not makes
modelform bound automatically

i'm expect that model validation also triggered as pointed here
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-is-valid-method-and-errors
but models.py contradicts
def is_valid(self):
"""
Returns True if the form has no errors. Otherwise, False. If
errors are
being ignored, returns False.
"""
return self.is_bound and not bool(self.errors)

model with instance only WILL NOT trigger validation

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.