I have the model Called Plan
Plan has state and city associated with it
I have other Model called Weather which has data at variious times during per day for each city in state
Now i want to get all the Plan objects with extra dictionary called weather.
Steps are
- Get all the plan objects
- Now based on the state and city each plan will have many rows in weather table
- i want to aggreagte all the columns .eg if i have five rows for that city and state
and temperature values are
20 , 21 , 22 , 23 , 24. then i want take the avg of all the temperatues i.e 22 and store in new dictionary in plan model
so that i can access Plan.weather.temperature and it comes 22
I can use the for loop but that will be lot db queries . can do that on one query or what ever option is possible
EDIT:
class Plan(model.model):
name = tinymce_models.HTMLField(blank=True, null=True)
region = models.ForeignKey(Region)
district = models.ForeignKey(District)
class Weather(model.model):
region = models.ForeignKey(Region)
district = models.ForeignKey(District)
temp_max = models.IntegerField(blank=True, null=True, verbose_name='Max temperature (C)')
temp_min = models.IntegerField(blank=True, null=True, verbose_name='Min temperature (C)')