From b6c44f4aca9a5ce621bbf6a24dba5f5dab68067c Mon Sep 17 00:00:00 2001 From: Philip Sargent at home Date: Tue, 31 Dec 2024 07:01:13 +0000 Subject: [PATCH] QuerySet ref - online edit of handbook/troggle/trogforms.html --- handbook/troggle/trogforms.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/handbook/troggle/trogforms.html b/handbook/troggle/trogforms.html index 44e445b4a..7c6f8eb15 100644 --- a/handbook/troggle/trogforms.html +++ b/handbook/troggle/trogforms.html @@ -30,7 +30,7 @@

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 <form> ....</form> tags. -

It might help you at this point to remind yourself how an ordinary webapge works, without a form. So look at a logbook entry which just displays the data and the corresponding template logbookentry.html. +

It might help you at this point to remind yourself how an ordinary webapge works, without a form. So look at a logbook entry which just displays the data and the corresponding template logbookentry.html... OK, not such a good idea: that is quite complicated. See For loop below.

HTML <form> and fields

But if you haven't worked with HTML forms before, then you actually have a whole lot of HTML you will need to learn from scratch: how the <form> ....</form> 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 ModelForms

A few of our data entry pages use ModelForms, 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. + +

For loop

_ +[This section to be moved to a generic Django Templating page] +

In logbookentry.html you will see the Django template code + {% for personlogentry in logbookentry.personlogentry_set.all %} + 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 function "_set" applied followed by the QuerySet function ".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. + +


Go on to: Troggle: updating Django
Return to: Troggle programmers' guide