How Django inlineformsets works internally

15 views
Skip to first unread message

Paul

unread,
Oct 10, 2017, 11:31:00 AM10/10/17
to Django users
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) and I want to understand how the mechanism is working.

Reply all
Reply to author
Forward
0 new messages