Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I display items on Django form based on data in a table?
    primarykey
    data
    text
    <p>I am trying to figure out how to display a form based on data from a table. I basically want to use the data from one table as a label to enter data that goes into another table.</p> <p>I have two food tables:</p> <pre><code>class FoodType(models.Model): name = models.CharField(max_length=200) class Food(models.Model): foodtype = models.ForeignKey(FoodType) tracktemp = models.BooleanField(verbose_name="Track Temperature?") </code></pre> <p>and a Temp table like this:</p> <pre><code>class Temp(models.Model): date = models.DateField('Entry Date') time = models.TimeField('Entry Time') food = models.ForeignKey(Food) temp = models.IntegerField(max_length=4, blank=True, null=True) </code></pre> <p>I have two foods in my <code>Food</code> table (Beans, Sprouts) and <code>tracktemp</code> is set to <code>True</code> for each of them.</p> <p>In the Temp table I want to be able to add multiple records, each of which has a single temp at a particular time. For example:</p> <pre><code>Beans 1st Dec 2012 6.00pm 230 Beans 1st Dec 2012 6.04pm 235 Beans 1st Dec 2012 6.10pm 240 </code></pre> <p>To do this I want to be able to render a form like this to enter the temps:</p> <pre><code>Beans [ ] Sprouts [ ] [save] </code></pre> <p>Some notes about the above form:</p> <ul> <li>The food names should be labels, not combo boxes.</li> <li>I will not show the date/time fields and just programmatically set them.</li> </ul> <p>As such I need to find all items in the Food table that have <code>tracktemp</code> set to 'True' and use that to present a form to the user so the user can add a temp for that time.</p> <p>How can I do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload