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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:37:33+00:00 2026-05-20T08:37:33+00:00

I have an action that a user can do many times a day. I’m

  • 0

I have an action that a user can do many times a day. I’m trying to get a count of how many times the user has taken that action, but only for today’s date. Here’s the way I’m currently solving this, but is there an easier way? I feel like I should be able to fit this in one line. 🙂

today_slaps = 0
slaps = Slap.objects.filter(from_user=request.user.id)
for slap in slaps:
    if slap.date.date() == datetime.now().date():
        today_slaps += 1

The logic I’m looking for is:

slaps = Slap.objects.filter(from_user=2, date.date()=datetime.now().date()).count()

But that’s obviously throwing an error that a keyword can’t be an expression. Sorry if this is a basic one, but thoughts?

  • 1 1 Answer
  • 1 View
  • 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-20T08:37:34+00:00Added an answer on May 20, 2026 at 8:37 am
    slap_count = Slap.objects.filter(from_user=request.user, \ 
                          date__gte=datetime.date.today()).count()
    
    # specifically setting datetimefield=datetime.date.today() won't work
    # gte = will work for datetimefield vs datetime object starting at that date
    # it's also assumed there will never be a slap from the future. 
    

    Generates the following SQL:

    SELECT ... FROM ... WHERE ... date >= 2011-02-26 00:00:00 
    

    So it’s safe to say you will only get today’s slaps, again, unless you have slaps from the future. If you do, I’d set every date__day, date__year, date__month explicitly.

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

Sidebar

Related Questions

I have a Rails controller action to test. In that action, a method User.can?
I have an action that relies on User.Identity.Name to get the username of the
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I have an action method VerifyNewUser() that gets called when the user clicks a
I have a User entity that has a Current Location field (city and country).
I know that this question might have been asked like 100 times, but, believe
i have an action that return a file content. i added: Response.AddHeader(Content-Disposition, attactment; filename:\
I have an Action that basically adds an item to a cart, the only
I have an action that lets the customer preview system email messages and i
Suppose I have an action that returns an rendered asp.net mvc control and send

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.