You might want to look at stuff that has already been developed.  (No need to 
reinvent the wheel, right?)
Check out this jQuery plugin for making a dynamic formset:
https://github.com/elo80ka/django-dynamic-formset

You might find some answers there.

From: [email protected] 
[mailto:[email protected]] On Behalf Of [email protected]
Sent: Friday, October 13, 2017 7:59 AM
To: Django developers (Contributions to Django itself)
Subject: How Django inlineformsets works internally

Hello,

First I know, this is for django developers, but I asked on django-users, 
stackoverflow, udemy etc and I never got an answered, so this is my last 
options, to ask the developers.

I checked the Django code for BaseFormset, 
modelform_factory,modelformset_factory,formset_factory etc but not everything 
is clear for me.

-----------------

I have a form with two inline formsets.
.

At the HTML level Django use the hidden fields for the formset management, and 
use the prefix to know which fields are related to a formset.

Also it has ids in the html id, to group like in a virtual form the fields.



<input name="documents-0-document" id="id_documents-0-document" type="file">
<input name="documents-0-filename" class="vTextField" maxlength="255" 
id="id_documents-0-filename" type="text">
<input name="documents-0-DELETE" id="id_documents-0-DELETE" type="checkbox">



On retrieve by default I get the path to the file in a paragraph and the inputs 
(html elements) are empty.



 <p class="file-upload">Currently:
<a href="/media/Test%20Insieme/documents/sdsasa7">Test 
Insieme/documents/sdsasa7</a><br>
<input name="documents-0-document" id="id_documents-0-document" type="file">
Change:
</p>



On Browse(upload a different file) Django knows to update the same record in 
the database. Similar for click on checkbox.



How Django make the correlation between the paragraph that show the path, the 
html id of the element and what is in the database?



I want to change the UI (make it dynamic with JavaScript, use button instead of 
checkbox for delete) and I want to understand how the mechanism is working 
because I need to do two very customize formsets.



Thank you!
--
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 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/e8690a9c-a8b8-4cab-bc64-7ff01f36ff8a%40googlegroups.com<https://groups.google.com/d/msgid/django-developers/e8690a9c-a8b8-4cab-bc64-7ff01f36ff8a%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/8fc8458b364241ff8ffe94b8ca029b32%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to