Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8768883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:11:00+00:00 2026-06-13T17:11:00+00:00

I have the model Called Plan Plan has state and city associated with it

  • 0

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

  1. Get all the plan objects
  2. Now based on the state and city each plan will have many rows in weather table
  3. 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)')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:11:01+00:00Added an answer on June 13, 2026 at 5:11 pm

    Depends on your model but something like this:

    Plan.objects.filter(region__name="CA").annotate(avg_temperature=Avg("region__weather__temp_max"))

    The avg_temperature field will now be available on the objects returned by the query. This name is customizable based on the keyword argument provided to annotate.

    Or take a look here: https://docs.djangoproject.com/en/dev/topics/db/aggregation/

    Django has these kinds of queries built in. If the aggregation and annotation api can’t facilitate this (seems like a strong candidate for working out of the box) then you have the option of writing a raw query:

    https://docs.djangoproject.com/en/dev/topics/db/sql/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called Answer which has a ForeignKey relationship to another model
I have a Model called statistics which has a value field that contains Goals
Let's say I have a model called Theme, which has several attributes setting interface
I have a model called Movie, which has a ManyToManyField called director to a
I have a model called Locality, which is basically a city (or a suburb
I have a model called 'BusinessPage' which can be associated with 1 or more
I have a model called Event and another called Product. An event has many
I have a model called Contact which has_one guest like so. class Contact <
I have model called Product and it has the following columns: create_table :products do
I have model called User with a has_many relationship to UserFilter . UserFilter has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.