QuerySet ref - online edit of handbook/troggle/trogforms.html

This commit is contained in:
Philip Sargent at home
2024-12-31 07:01:13 +00:00
committed by Expo on server
parent 8076b9c4d3
commit b6c44f4aca

View File

@@ -30,7 +30,7 @@
<p>Hah, that was a nasty shock wasn't it? OK, most of that stuff is not the stuff which manages the data entry form. Concentrate on just the bits between the &lt;form&gt; ....&lt;/form&gt; tags. <p>Hah, that was a nasty shock wasn't it? OK, most of that stuff is not the stuff which manages the data entry form. Concentrate on just the bits between the &lt;form&gt; ....&lt;/form&gt; tags.
<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>. <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>... OK, not such a good idea: that is quite complicated. See <a href="#forloop">For loop</a> below.
<h4>HTML &lt;form&gt and fields</h4> <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", and how tag attributes such as "disabled" or "required" work. 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.
@@ -41,6 +41,14 @@ But if you haven't worked with HTML forms before, then you actually have <a href
<h3>ModelForms</h3> <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. If you can't find where something is initialised, it is probably because it was done automatically and invisibly by instantiating a ModelForm. <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.
<h3 id="forloop">For loop</h3> _
[This section to be moved to a generic Django Templating page]
<p> In <a href="/repositories/troggle/.git/tree/templates/logbookentry.html">logbookentry.html</a> you will see the Django template code
<code>{% for personlogentry in logbookentry.personlogentry_set.all %}</code>
which illustrates the for loop syntax, but also the my_object.attribute syntax, where the attribute is a one-to-many link to other Objects (instances of a Class) and has the <em>function</em> "_set" applied followed by the <a href="https://docs.djangoproject.com/en/5.1/ref/models/querysets/#django.db.models.query.QuerySet.all">QuerySet function</a> ".all". The effect of the for loop is to iterate through all the "personlogentry" instances referenced by the specific "logbookentry" the page is looking at.
<hr /> <hr />
Go on to: <a href="trogdjangup.html">Troggle: updating Django</a><br /> Go on to: <a href="trogdjangup.html">Troggle: updating Django</a><br />
Return to: <a href="trognotes.html">Troggle programmers' guide</a><br /> Return to: <a href="trognotes.html">Troggle programmers' guide</a><br />