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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:28:11+00:00 2026-05-23T00:28:11+00:00

Hello i’m working on a blog app and I have a model: class Post(models.Model):

  • 0

Hello i’m working on a blog app and I have a model:

class Post(models.Model):
    title = models.CharField(max_length=255)
    <..>
    is_published = models.BooleanField(default=False)                                  
    time_publish = models.DateTimeField()
    time_edit = models.DateTimeField(auto_now=True)
    time_create = models.DateTimeField(auto_now_add=True)

And i want to set that, when user sets is_published=True and .save() is called then time_publish would save current time.

The problem is that i don’t know what route i should take. Overwrite .save() or make something with signals or what? I would appreciate some links to Docs.

Sorry if it’s dublicate but i din’t knew how the question of such matter should be named.

Update:

So thanks to manji i produced this code that works:

def save(self, *args, **kwargs):
    if self.pk is not None:
        orig = Post.objects.get(pk=self.pk)
        if not orig.time_publish and self.is_published:
            self.time_publish = datetime.now() 
        elif not self.is_published:
            self.time_publish = None
    super(Post, self).save(*args, **kwargs)   
  • 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-23T00:28:12+00:00Added an answer on May 23, 2026 at 12:28 am

    The simplest solution (and django compliant) is to override your model’s save method.

    class Post(models.Model):
        ...
    
        def save(self, *args, **kwargs):
            if self.is_published:
                self.time_publish = datetime.now() # don't forget import datetime
            super(Post, self).save(*args, **kwargs)
            ...
    

    More informations here: Overriding predefined model methods

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

Sidebar

Related Questions

Hello in my java class Toto, I have 3 static methods I would like
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello can anybody solve this please I'm creating the object in the action class
Hello , I am currently working on the student association's website. The student's association
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello we have an SQL server application running over a low bandwith connection. We
Hello I have two dependants select box, the second one is popularited after onchange
Hello everyone i have big query to calculation and counter by clinic ID SELECT
Hello I have a Problem with some Buttons I would like to create a
Hello I'm using Gtk on C, I need to have a GtkTextView in the

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.