A Python library to provide easy old records management for Django models
Reason this release was yanked:
Broken
Project description
Django Old Records
A simple Django app with tools to manage old records of Django models
Install
pip install django-old-records
Add django_old_records
to your project's INSTALLED_APPS
Usage
There is a manager that decides if a record is too old based on a date field (created_at
by default) and a max_age
. Ex.:
from django_old_records import OldRecordsManager
from django.db import models
class Cat(models.Model):
name = models.CharField()
created_at = models.DateTimeField(auto_now_add=True)
max_age = 365 * 20 # 20 years
old_records = OldRecordsManager()
Cat.old_records.all() # lists all cat records older than 20 years
max_age
could be an integer representing days or a python timedelta
for a more detailed value. Ex.:
from django_old_records import OldRecordsManager
from django.db import models
from datetime import timedelta
class Cat(models.Model):
name = models.CharField()
created_at = models.DateTimeField(auto_now_add=True)
max_age = timedelta(hours=4, seconds=20)
old_records = OldRecordsManager()
Cat.old_records.all() # lists all cat records older than 4 hours and 20 seconds
If your model's created_at
has a different name you can specify it with the created_at_field
attribute. Ex.:
class Cat(models.Model):
name = models.CharField()
was_born = models.DateTimeField(auto_now_add=True)
created_at_field = 'was_born'
max_age = 365 * 20 # 20 years
old_records = OldRecordsManager()
There is also a management command that deletes all old records from all models with the old_records
manager:
python manage.py delete_old_records
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_old_records-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dd58db094782146763ad9eadea506d60641b39e458b4c5bd4cf39ba3c8deac4 |
|
MD5 | b3022c5f7e3f3aace6f3f7724d162d0e |
|
BLAKE2b-256 | f1b7cad34f454700059a031626ef9ecfd3dea0d989bec872005f8c9ce58dc397 |