- Import the necessary module:
from django_cron import Job
- Create a new class that inherits from the
Job
class:
class YourCleanupJob(Job):
...
- Implement the
run
method within this class. This is where you define the cleanup logic:
def run(self):
# Your cleanup logic goes here
...
- Add any necessary parameters to the
run
method for customization:
def run(self, args, *kwargs):
# Your cleanup logic using any provided parameters
...
- Register the job with Django's cron scheduler by adding it to the
CRON_CLASSES
setting in settings.py:
CRON_CLASSES = [
"your_app_name.path.to.YourCleanupJob",
...
]