I am working on a project, aim of the project is that user creates announcement and I need to change is_active
status to False
automatically after 30 days so announcement be active 30 days but I have no idea how to do that, I am using Django Rest Framework and VueJs.
CodePudding user response:
You would need to have a task system set up, something like celery.
Then have a task that runs daily getting announcement objects with a created date of greater than 30 days.
Once you have those objects you can set the is_active status to False.
CodePudding user response:
You can create a custom command for django which you can run with crontab every day. With this command you select everything with a creation-date greater than 30 days
CodePudding user response:
This is not all this is only Little help......
import datetime
import calendar
def add_months(sourcedate, months):
month = sourcedate.month - 1 months
year = sourcedate.year month // 12
month = month % 12 1
day = min(sourcedate.day, calendar.monthrange(year,month)[1])
return datetime.date(year, month, day)