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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:50:01+00:00 2026-05-27T11:50:01+00:00

Assume I have a Django model with the following fields: class Gizmo(models.Model): date_created =

  • 0

Assume I have a Django model with the following fields:

class Gizmo(models.Model):
    date_created = models.DateTimeField(auto_now_add=True)
    date_updated = models.DateTimeField(auto_now=True)

When I create a gizmo, can I be sure that Django will generate identical timestamps for the two fields? I’m worried that Django might create a datetime instance for each, and that these will produce slightly different timestamps. It’s important that the timestamps be identical so that there’s a reliable way to determine whether the gizmo has been updated (i.e. it has been if the timestamps differ).

  • 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-27T11:50:01+00:00Added an answer on May 27, 2026 at 11:50 am

    Based on one test I can tell you the answer is no.

    test = TestModel.objects.create()
    print test.date_created
    # Out: datetime.datetime(2011, 12, 12, 20, 51, 41, 620985)
    print test.date_last_modified
    # Out: datetime.datetime(2011, 12, 12, 20, 51, 41, 621008)
    

    I’d just override the save method on your model and populate these values myself.

    PS: I did just look at the field code first, but ended up just running the actual test since I wouldn’t have known if django does something on a model level somewhere if there are two auto_now-type fields or something.

    # datetimefield
    def pre_save(self, model_instance, add):
        if self.auto_now or (self.auto_now_add and add):
            value = datetime.datetime.now()
            setattr(model_instance, self.attname, value)
            return value
        else:
            return super(DateTimeField, self).pre_save(model_instance, add)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume we have following models: from django.db import models class Foo(models.Model): name =
lets assume I have following model: class Note(models.Model): user = models.ForeignKey(User) pub_date = models.DateTimeField()
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
If have the following Django (1.4) model: from django.db import models class SimpleModel(models.Model): name
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
Assume a django model with two fields: - created - modified Each field are
I have the following Django Model which retrieves 3 records from a database. The
I have a model which is essentially just a string (django.db.models.CharField). There will only
I have a Model and ModelForm like: from django.utils.translation import ugettext_lazy as _ class
Suppose I have this model: class PhotoAlbum(models.Model): title = models.CharField(max_length=128) author = models.CharField(max_length=128) class

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.