ModelForm - online edit of handbook/troggle/trogforms.html

This commit is contained in:
Philip Sargent at home
2024-12-31 06:45:15 +00:00
committed by Expo on server
parent f3d2704cc4
commit 8076b9c4d3

View File

@@ -21,7 +21,9 @@
<p>This is now a hint that you need to refresh your knowledge of <a href="https://docs.djangoproject.com/en/5.1/topics/templates/">the Django template system</a>. Fortunately you only need to know a tiny part of this to work with forms, basically just this idiom:
<code>{{ my_object.attribute }}</code>
and maybe also
<code>{{ my_dict.key }}</code>
<code>{{ my_dict.key }}<br>
{{ my_variable }}<br><br><br>
{% if my_variable %} ... {% endif %} </code>
<p>Now have a look at the Django templates for some of the forms you will already be familiar with from using them as a caver entering data, e.g. <a href="/logbookedit/2024-08-01c">Logbook entry editing</a> which uses the Django template <a href="/repositories/troggle/.git/tree/templates/logbookform.html">logbookform.html</a>...
(This is one of those webpages where we do not use a Form object for writing the HTML, only for interpreting the results).
@@ -31,14 +33,14 @@
<p>It might help you at this point to remind yourself how an ordinary webapge works, without a form. So look at <a href="/logbookentry/2024-08-01/2024-08-01c">a logbook entry</a> which just displays the data and the corresponding template <a href="/repositories/troggle/.git/tree/templates/logbookentry.html">logbookentry.html</a>.
<h4>HTML &lt;form&gt and fields</h4>
But if you haven't worked with HTML forms before, then you actually have <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form">a whole lot of HTML</a> you will need to learn from scratch: how the <code>&lt;form&gt; ....&lt;/form&gt; </code> tag works, and how fields and labels and stuff works, and "input" and "textarea" and "submit".
But if you haven't worked with HTML forms before, then you actually have <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form">a whole lot of HTML</a> you will need to learn from scratch: how the <code>&lt;form&gt; ....&lt;/form&gt; </code> tag works, and how fields and labels and stuff works, and "input" and "textarea" and "submit", and how tag attributes such as "disabled" or "required" work.
<p>
You will also need to know about <a href="https://docs.djangoproject.com/en/5.1/ref/forms/widgets/">Django Widgets</a>.
<p>So that's enough to get you started. Now you are on your own, apart from help on the Website room of the Matrix chat and the nerd email list of course.
<h3>ModelForms</h3>
<p>A few of our data entry pages use <a href="https://docs.djangoproject.com/en/5.1/topics/forms/modelforms/">ModelForms</a>, these are where the Form object is automagically created from a Model class.
<p>A few of our data entry pages use <a href="https://docs.djangoproject.com/en/5.1/topics/forms/modelforms/">ModelForms</a>, these are where the Form object is automagically created from a Model class. If you can't find where something is initialised, it is probably because it was done automatically and invisibly by instantiating a ModelForm.
<hr />
Go on to: <a href="trogdjangup.html">Troggle: updating Django</a><br />
Return to: <a href="trognotes.html">Troggle programmers' guide</a><br />