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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:01:51+00:00 2026-05-15T17:01:51+00:00

I have a simple article model with pub_date field and a unpublish_date field. Is

  • 0

I have a simple article model with pub_date field and a unpublish_date field.

Is there any way to automagically set my is_published field to False when the unpublish_date is in the past?

class Article(models.Model):
    title = models.CharField(max_length=500)
    post = models.TextField(blank=True, null=True,)

    pub_date = models.DateTimeField(default=datetime.datetime.now)
    unpublish_date = models.DateTimeField(blank=True, null=True)
    is_published = models.BooleanField(default=True,)
  • 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-15T17:01:52+00:00Added an answer on May 15, 2026 at 5:01 pm

    You can simply factor this unpublish_date into your queries, for example:

    articles_to_show = Articles.objects.filter(is_published=True,
                                            unpublish_date__gt=datetime.date.today())
    

    This is likely to make your code more complicated, though. You’d have to rewrite all your queries to be aware of the unpublish_date.

    Cron works for this sort of thing but is only good for changing things in large batches once or a few times a day. It doesn’t scale well when you have a large batch of tasks to do or want more fine-grained scheduling.

    If running a task via cron once per day is sufficient, do that. It might be worth investigating more advanced options such as message queues, though.

    To make a scheduled task which will run at a precise time (provided a worker is available), I would use Celery.

    from celery.decorators import task
    
    @task
    def unpublish(article_pk):
        article = Article.objects.get(pk=article_pk)
        article.is_published = False
        article.save()
    
    # Unpublish article in exactly 7 days from now
    from datetime import datetime, timedelta
    unpublish.apply_async([article.pk], eta=datetime.now() + datetime.timedelta(7))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple article model with a predefined_title attribute and a user_defined_title attribute
Hay all, i have a simple model like this def Article(models.Model): upvotes = models.ManyToManyField(User,
I have a simple model that is defined as: class Article(models.Model): slug = models.SlugField(max_length=50,
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I have a really simple Rails app. Basically an article with comments. I want
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
In the Photo model I have following simple rule: searchable do string :note end
I have an app called CMS with Category and Article. Quite simple. I overwrite
I have a model with TranslateBehavior attached to it and I wonder if there
I have two models for Publications and Employees: class Publication(models.Model): BOOK_CHAPTER = 1 ARTICLE

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.