The great thing about dates in python, and peewee in particular is that you can compare them in a pretty intuitive way. Behind the scenes dates are typically represented as number of seconds since some date in 1970. Here's an example of querying by date with peewee:
today = datetime.today()
query = Tweet.update(is_published=True).where(Tweet.creation_date < today)
query.execute()
In this example the Tweet
class is just one with a boolean is_published
attribute, and a datetime creation_date
attribute.
Something closer to your example would be:
today = datetime.today()
query = Assignment.select().where(Assignment.due_date < today)
But I'll try not to completely give the answer away.
Hope that helps, let me know if you have any questions.
manpreet
Best Answer
2 years ago
I'm building a web app which allows professors to input assignments for students to follow along with, an interactive syllabus if you will. One of the sections of a course page displays progress.
I have built a pie graph component which I'd like to populate with data:
I'm using the Peewee ORM to retrieve this data from my assignments table:
I need the following from the database and I'm not sure how to accomplish it with Peewee. Getting the name, and total should be simple. But I need to compare the due_date to today's date to see how many of the assignments are completed.
Name Total Completed
Final 2 0 Homework 23 12 Test 4 2
My pie chart output will look something like this if it matters:
UPDATE
I've got a query that does almost everything I need. Can anyone help me take it the rest of the way?
Here's the query:
And here's the result using the sample data below:
This is really close, but I would expect the completed column to be specific to the assignment type.
Here's some sample data from the Assignment table