#12780: Provide a hook for compound form/formset validation in ModelAdmin
----------------------------------+-----------------------------------------
 Reporter:  mrts                  |       Owner:  nobody    
   Status:  new                   |   Milestone:            
Component:  django.contrib.admin  |     Version:  SVN       
 Keywords:                        |       Stage:  Unreviewed
Has_patch:  0                     |  
----------------------------------+-----------------------------------------
 Sometimes it is necessary to validate inline formset data based on the
 main form data and vice-versa.

 See e.g. http://groups.google.com/group/django-
 users/browse_thread/thread/259c1679ddaaceb8/6ad3698e5451d3fe for a use
 case.

 My use case is somewhat similar: an object can be published only if its
 associated items meet certain criteria. Thus, to validate the "is
 published" flag in the form, access to formsets is required.

 For advanced users a simple change is sufficient: substitute `if
 all_valid(formsets) and form_validated:` with `if
 self.formsets_are_valid(formsets, form, form_validated) and
 form_validated:` in `admin/options.py`, where `def formset_are_valid(self,
 formsets, ...): return all_valid(formsets)`. The latter can then be
 overriden for arbitrary further manipulations. Will upload a patch
 eventually.

 However, this means that people have to mess with either `Form` or
 `FormSet` internals directly (`_non_form_errors` etc) to expose the
 errors.

 This is yet another proof of a conceptual problem, quoting myself from
 http://groups.google.com/group/django-
 developers/browse_thread/thread/f9aae709a7fda689/fb16a17ab6a31931 :

 "''Inline formsets usually represent
 composition, i.e. the inline objects are inseparable from the
 main entity. The relation is stronger than a ForeignKey (from the
 main entity to another entity), yet the latter is displayed as a
 field of the form and can be easily manipulated -- but not the inlines.''"

 So, this is yet another reason for introducing !FormsetFields in the long
 run -- `Form.clean()` would have access to formsets both in the admin and
 ordinary forms.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12780>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to