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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:26:26+00:00 2026-06-10T01:26:26+00:00

We have a Django project where a User account is created for a person

  • 0

We have a Django project where a User account is created for a person whenever she calls us on the phone. The person may or may not, at a later point, use her account to log in to our website.

Question: How can I tell if a User has ever logged in to our website?

Clarification: I want to answer the question above for hundreds of existing users, not just for new users that are created from this point on.

Thought 1: Check User.last_login. Unfortunately Django initializes last_login to datetime.datetime.now() when the User is created, regardless of whether she ever logged in.

Thought 2: Check if User.last_login matches User.date_joined. Unfortunately Django initializes both these fields to datetime.now(), and they can be a few microseconds apart:

In [1]: u = User.objects.create(username="bla")

In [2]: u.date_joined - u.last_login
Out[2]: datetime.timedelta(0, 0, 23)

Current hack I am using: Assume the user has logged in at least once iff user.last_login - user.date_joined >= datetime.timedelta(seconds=1).

Is there a better way to tell if a User has ever logged in?

  • 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-10T01:26:28+00:00Added an answer on June 10, 2026 at 1:26 am

    I’m going to assume that you’re right when you say that both the date_joined and last_login are set to the current date on creation, and that for some reason there is enough time elapsed between the two assignments to create a noticeable delta.

    If that’s the case, then you could take @LAK’s advice and create either a pre_save (and check if the instance’s ID is 0) or post_save (and check the created parameter) and manually set the last_login field to either None or the same value as date_joined. From there all of your future data is preserved from the one-second fuzziness you seem to despise.

    As for your existing data, I think that you’re stuck making the best guess with the data you’ve got. I don’t see it as too risky to make the assumption that you’re making. If you wanted to clean it up to be the same as all new data, you could just update your database to set the last_login value. If you’re using South, this is easy enough to do with a data migration. Otherwise, you could just create a script to run after you deploy the new code changes.

    I honestly don’t think that it’s a problem that they’re off by a little bit. So long as you’re making the assumption that it’s most likely not humanly possible for a user to log in within the time frame that their account was created, there seems to be little reason to add a bunch of extra work to force it to be an exact match.

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

Sidebar

Related Questions

So I have a django project I just created called 'coolprojectsite' the directory structure
Short version: I have a Django project under development & testing (not yet into
In my django project I have 2 variations of users. One subclasses User class
I have a django project in which a user will type in a url
I have a Django 1.4 project that makes use of django-registration which calls a
I have a Django project that has two models: Group and Person. Groups can
I have a django project, but for some reason basic jquery isn't working. <html>
I have a Django project in which multiple processes are accessing the backend mysql
I have a django project that I have been working on as a solo
I have a django project which is laid out like this... myproject apps media

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.