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 342561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:48:57+00:00 2026-05-12T10:48:57+00:00

I have a bunch of objects that have a value and a date field:

  • 0

I have a bunch of objects that have a value and a date field:

obj1 = Obj(date='2009-8-20', value=10)
obj2 = Obj(date='2009-8-21', value=15)
obj3 = Obj(date='2009-8-23', value=8)

I want this returned:

[10, 15, 0, 8]

or better yet, an aggregate of the total up to that point:

[10, 25, 25, 33]

I would be best to get this data directly from the database, but otherwise I can do the totaling pretty easily with a forloop.

I’m using Django’s ORM and also Postgres

edit:

Just to note, that my example only covers a few days, but in practice, I have hundreds of objects covering a couple decades… What I’m trying to do is create a line graph showing how the sum of all my objects has grown over time (a very long time)

  • 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-05-12T10:48:57+00:00Added an answer on May 12, 2026 at 10:48 am

    This one isn’t tested, since it’s a bit too much of a pain to set up a Django table to test with:

    from datetime import date, timedelta
    # http://www.ianlewis.org/en/python-date-range-iterator
    def datetimeRange(from_date, to_date=None):
        while to_date is None or from_date <= to_date:
            yield from_date
            from_date = from_date + timedelta(days = 1)
    
    start = date(2009, 8, 20)
    end = date(2009, 8, 23)
    objects = Obj.objects.filter(date__gte=start)
    objects = objects.filter(date__lte=end)
    
    results = {}
    for o in objects:
        results[o.date] = o.value
    
    return [results.get(day, 0) for day in datetimeRange(start, end)]
    

    This avoids running a separate query for every day.

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

Sidebar

Related Questions

I have a bunch of objects in my application (Organisations, Individuals, Orders, etC) and
I have a bunch of objects in a flat structure. These objects have an
Dumb question. Lets say I have a bunch of person objects with their fields
I have a bunch of files that I need to be able to transport
I have a bunch of latitude/longitude pairs that map to known x/y coordinates on
I have a bunch of .NET frameworks installed on my machine. I know that
I have a bunch of classes I want to rename. Some of them have
I have a bunch of perfmon files that have captured information over a period
I have a bunch (hundreds) of files that are supposed to have Unix line
I have a function that receives three different people objects and generates a new

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.