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

  • SEARCH
  • Home
  • 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 7589293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:07:28+00:00 2026-05-30T20:07:28+00:00

I have a model which describes an event like this: class Event(models.Model): date =

  • 0

I have a model which describes an event like this:

class Event(models.Model):
    date = models.DateField()
    time = models.TimeField()

I would like to retrieve all future events (ie date greater than now.date()). However If date is today, I would like to retrieve today’s events with time greater than now.time().

This is what I am doing:

events = Event.objects.filter(date__gte=now.date()).filter(time__gte=now.time()).order_by('-date')

where now = datetime.datetime.now()

But this is wrong, because it gives me an empty set if the only event is tomorrow and its time is less than current time (for example if event is tomorrow at 09:00 and today is 19:00)

is this possible in django?

PS: I would like to avoid iterating through the set.

  • 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-30T20:07:29+00:00Added an answer on May 30, 2026 at 8:07 pm

    Use Q objects, which allow you to make queries with OR statements.

    from django.db.models import Q
    Events = Event.objects.filter(
        Q(date=now.date(),
        time__gte=now.time()
        |Q(date__gt=now.date())
    ).order_by('-date')
    

    Note that you might want to sort on the time field as well:

    order_by('-date', '-time')
    
    • 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 Contact which has_one guest like so. class Contact <
I have a class, which describe an object for parsing XML. This class contains
I have db.Model which has several properties as described below: class Doc(db.Model): docTitle =
I have model Foo which has field bar. The bar field should be unique,
I have a model which gets its data from a parser object. I'm thinking
I'm using ASP.NET MVC and have a model which has an image (byte array)
I have a model Foo which have a ForeignKey to the User model. Later,
I have a model Task which will HABTM many TaskTargets. When it comes to
I have an Entry model which has many Tag s. Tag s are added
I have an edmx model which I have draged 2 tables onto - One

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.