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.
I have two food tables:
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?")
and a Temp table like this:
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)
I have two foods in my Food table (Beans, Sprouts) and tracktemp is set to True for each of them.
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:
Beans 1st Dec 2012 6.00pm 230
Beans 1st Dec 2012 6.04pm 235
Beans 1st Dec 2012 6.10pm 240
To do this I want to be able to render a form like this to enter the temps:
Beans [ ]
Sprouts [ ]
[save]
Some notes about the above form:
- The food names should be labels, not combo boxes.
- I will not show the date/time fields and just programmatically set them.
As such I need to find all items in the Food table that have tracktemp set to 'True' and use that to present a form to the user so the user can add a temp for that time.
How can I do this?