Tuesday, October 10, 2017

How Django inlineformsets works internally

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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d5e2106e-ee4d-4272-8b37-d22ace33ed63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment