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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:19:32+00:00 2026-06-12T05:19:32+00:00

For our blogging platform, we have an Article model, that contains an updated datetime

  • 0

For our blogging platform, we have an “Article” model, that contains an “updated” datetime field:

class Article(models.Model):
    updated = models.DateTimeField(null=True, blank=True)
    ...

When an article gets opened by any visitor for the first time in 24 hours, we do some time consuming calculations on different model fields, subsequently saving the model to the database. With this, we also update our “updated” field to the current datetime.now().

if (datetime.now() - article.updated).days > 1:
    # do some time consuming calculations
    article.updated = datetime.now()
    article.save()

When an article is requested more or less simultaneously, the time consuming operations on the first request have not finished, yet, causing the once-per-day operation to start again on the same object (article.updated has still the old value). May it help calling article.save() additionally right before starting the calculations? Or it this data postponed from saving to the database until the request has finished?

  • 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-12T05:19:34+00:00Added an answer on June 12, 2026 at 5:19 am

    Use the queryset select_for_update introduced in Django 1.4 which does a row level locking in the database. All matched entries will be locked until the end of the transaction block, meaning that other transactions will be prevented from changing or acquiring locks on them. There are a few gotchas specific to datgabase backend so make sure to read up and test it before relying totally on it.

    Some other ways to do it independent of the implementation is by customizing your models to have a locked boolean attribute. Not very neat but a workable solution. See What is the simplest way to lock an object in Django

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

Sidebar

Related Questions

Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
Our company produces cross-platform software and we have Bamboo instance which is building projects
Our team (QA) is facing the following problem: We have a database that is
Our Application has a Class that wraps Jersey REST functionality. One Method is public
Our app sets the is_active field in User Model to False to represent a
Our Django project is getting huge. We have hundreds of apps and use a
Our websites article backend does not allow access to anything above </head> which prevents
I have to make a view that shows unrelated data from multiple tables. I
Our data model is separated into schemas on two databases. The schemas are used
Our company is a subscription based service with an iPhone/iPad app that allows our

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.