skip to Main Content

I have a hosted web app made with django and react. now i want to implement a system like- one user request for posting a blog at a specific time specific date. and on that day the post is posted even if the user is not logedin or open the app. how to automate this type of task. for database i am using sqlite3.

Now How can i implement this type of task schedulling system using Django and React

3

Answers


  1. First you need to package the logic you want to do into a script. I want to recommend to turn it into a django management command (here).

    Test that the command does the correct logic when you type: python manage.py <your-command-name>. After running this successfully the user should have a new post.

    Now you want to schedule that command. This can be done by a crontab on your host device. You could also use django-crontab. This will then periodically run that command.

    Login or Signup to reply.
  2. You can use library django-apscheduler.

    Create schedule CRON for check each post with status not published, and timepost < timenow. You can schedule for every second. But i prefer to set shcedule for every 5 / 15 minutes. Prevent your server overload.

    Or U can use apscheduler.triggers.date. To set schedule run on certain date

    Login or Signup to reply.
  3. for posting a blog at a specific time specific date

    You don’t need a scheduling system for this, if I understand your intent correctly.

    Simply only show posts whose publication date is in the past:

    from django.utils.timezone import now
    
    
    class BlogPost(models.Model):
       published_on = models.DateTimeField(db_index=True)
       ...
    
    
    def my_view():
       public_posts = BlogPost.objects.filter(published_on__lte=now())
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search