On 06/08/2015 04:11 AM, Patryk Zawadzki wrote:
> 2015-06-07 10:18 GMT+02:00 Shai Berger <s...@platonix.com>:
>> Semi-devil's-advocate suggestion: Replace the management form with a
>> management field, a hidden field with
>>
>>         name = "__manage__%s" % (formsetname)
>>
>> and
>>
>>         value="x"
>>
>> Then instead of taking the number of forms from a field on a management form,
>> we can just take the accumulated length of the management field (which would 
>> be
>> returned as an array). This also offers a better solution to the checkboxes-
>> only-form problem, I think.
> 
> This is what Rails prefers but I think it is only added for checkbox fields.
> 
>> Do we use the management form for anything other than counting forms in the
>> formset?
> 
> Yes, we currently have the concept of initial forms even for bound
> formsets. This does not mirror form behaviour as bound forms don't
> have the concept of initial data. I'd like to get rid of that as well
> but Russell is not sure whether there are cases that require initial
> forms to work correctly.

There definitely are a number of cases that require initial forms to
work correctly, as can be easily seen by simply grepping for
`initial_form_count`. It's especially heavily used by the
inline-formsets code.

The formsets code is complex and fragile in general, IMO. I've often had
the feeling that a rewrite could simplify it and make it more robust,
though it's hard to say for sure without actually attempting such a rewrite.

But I think such a project needs to be approached as a full rewrite,
probably first as a third-party module and then later (if it works out
well) considered for merge as a separate replacement module. It does not
seem likely to me that tugging on individual threads like "remove
management form" and "remove initial forms" will result in changes to
the current formset code that are both backwards-compatible and an
improvement in the design. I'm willing to be proven wrong, but so far
the current pull request only strengthens that feeling.

Also, it's important to note that many people (including the admin) are
using the management form fields in JS code to allow for dynamic
formsets, so backwards compatibility needs to take that into account as
well.

I think it will be much more productive to focus on minimalist changes
that address the problem of a missing management form causing a 500
error, without trying to deeply change the design of the formsets code.

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/5575DD65.60902%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to