Skip to main content

A Python library to provide easy old records management for Django models

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-old-records-2.0.8.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

django_old_records-2.0.8-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file django-old-records-2.0.8.tar.gz.

File metadata

  • Download URL: django-old-records-2.0.8.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.9

File hashes

Hashes for django-old-records-2.0.8.tar.gz
Algorithm Hash digest
SHA256 a17a1c9ea3e20f38c5583a20087852dd092ab853018fc1a0df77b1e3e7158e08
MD5 7abfc594a41393a06d08fdc8f734685c
BLAKE2b-256 f91cd9077789881827d0f4674234c62b4c85636e1b4b431462a4624d687bdeba

See more details on using hashes here.

File details

Details for the file django_old_records-2.0.8-py3-none-any.whl.

File metadata

  • Download URL: django_old_records-2.0.8-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.9

File hashes

Hashes for django_old_records-2.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d0eac858ee4cddc1846a9aee8a0488f94dedeb6910157d8bad81c3df11eae024
MD5 1b6d9dc3298fd41c31b03dfa763003df
BLAKE2b-256 43f39c1c4b47e7ccf2987e049ee03ccaf0b5fa2e583594fe529d21fb82d53e62

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page