-1

I want to remove object after one day. Here is part of my code:

data = models.DateField(null=True)

So for example value of data field is

10.10.2017

And I want to remove it in

11.10.2017

Thanks for help !

xaos_xv
  • 759
  • 1
  • 10
  • 27
  • this is a very bad formatted question, please take a look at the help page (https://stackoverflow.com/help) to read how to ask a good question. That said, you probably are looking for a scheduled task, and celery (http://www.celeryproject.org/) may be the tool you're looking for. – abidibo Oct 17 '17 at 15:08

1 Answers1

2

To accomplish something like this you will need to create a periodic task using celery or a cron job that runs every day and removes all the data from the previous day.

You can use the current date as reference and get old data that is not from today using to_delete_data = ModelName.objects.filter(data__lt=current_date)

If you want to delete just previous day you will need to use timedelta to get the starting point of the previous day and chain the filters to get the correct data.

Anshul
  • 387
  • 3
  • 15