How to automatically delete records from database after a specific time in Django

Nouman Javed

I have a model named 'Complaint' with numerous entries and I want to delete the entry if it is in database for more than 3 days. How can I do that is there any query for specifying the time. I'm also storing the time at which the entry was stored. This is my models.py file.

complaint_for = models.CharField(max_length=25, choices=COMPLAINT_CHOICES, default='Misbehave')
name = models.CharField(max_length=50)
created = models.DateTimeField(auto_now_add=True)
t_e_o

To be honest, I have never worked worked with Django, but as far as I know, a good solution to delete records after a certain time interval, is to run automatically a database script. In your case, I can imagine that you have somewhere in your db-table a column which is named creation_time or something like that and then with your script you can just check if the difference between the current time and the creation_time is more or equal to the specified time interval. If so, the script deletes the record. In order to run such a script automatically, you can start a cron job . You can read more on the topic how to delete records with sql here and here on the topic cron jobs.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to automatically remove data from firestore after a specific time?

How to delete records from database correctly

Automatically delete data from database table after execution of SQL statements

How to delete some records or files after X time - Laravel 5

How To Delete a Specific User from Database?

How to delete a node from the firebase real-time database after creating another node with same IDs

How to make kivy window close automatically after specific amount of time?

How to automatically close an Interstitial Ad after specific amount of time?

How can I automatically shutdown the system after a specific time?

How to Run Ajax request automatically after a specific time?

How to delete specific range of records from a GROUP BY query?

How To Delete All Records From Database All Tables

How to delete all records from the database that match my criteria

delete objects inParse after a set amount of time from a specific class

Delete an entity from database after a certain amount of time

How to automatically delete Firebase inactive users from database and authentication?

Meteor - How to automatically remove a single item from a collection after a specific time period from within a server side method?

Django Automatically Update Records after a certain timespan

Userform to delete specific records from table always duplicates the last record after deleting a specific record

Rails how to sort records from database in a specific order?

How to show records in php from database in specific order

How to display only specific records from a database table in MVC?

Mongoose delete records after certain time

Delete an object automatically after specified time

Delete a specific field from a database

In Django, how do I select 100 random records from the database?

Redis doesn't delete records from the database

Unable to delete multiple records from the database

How to delete a specific record from database mysql by using Volley

TOP Ranking

HotTag

Archive