Skip to main content

this library adds 'created_at', 'updated_at' and 'delete_at' fields like a rail apps in django, also added soft delete method

Project description

build Open Source Love svg3 license release download GitHub stars

django-paranoid

this library adds 'created_at', 'updated_at' and 'delete_at' fields like a rail apps in django, also added soft delete method.

install

pip install django-paranoid

How to start

1.- Add to django-paranoid in the django apps:

INSTALLED_APPS = [
    'django.contrib.admin',
  'django.contrib.auth',
        ...
  'django_paranoid'
  ...
]

2.- Extends ParanoidModel in the model to use:

from django_paranoid.models import ParanoidModel

class MyModel(ParanoidModel):
    field = models.CharField(max_length=20)

3.- Add to django-admin:

from django_paranoid.admin import ParanoidAdmin

class MyModelAdmin(ParanoidAdmin):
    pass
  ...
admin.site.register(MyModel, MyModelAdmin)

Soft Delete

m = MyModel.objects.last()
m.delete()

This only applies soft delete, so the record will remain in the database, but it will not be visible for normal queries:

m = MyModel.objects.last()
>>> m
>>>

Now the record has a deleted_at field and if do you want show the delete record you could using 'objects_with_deleted':

m = MyModel.objects_with_deleted.last()
>>> m
<MyModel: name>
>>> m.deleted_at
datetime.datetime(2019, 8, 10, 6, 16, 44, 633727, tzinfo=<UTC>)

Restore Soft Delete

On object which was soft deleted, follow steps above to restore object

m.restore()

Hard Delete

If do you want to delete record from DB, you only should using True param:

m = MyModel.objects.last()
m.delete(True)

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-paranoid-1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

django_paranoid-1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file django-paranoid-1.0.tar.gz.

File metadata

  • Download URL: django-paranoid-1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for django-paranoid-1.0.tar.gz
Algorithm Hash digest
SHA256 17771ff2f20e1a151d10039080de15fcae9338abb9b90fca44b59cd00a0d1118
MD5 ed4d9c5a8870b2b5893429103d7111e2
BLAKE2b-256 31dd0a0ab57be112bc253b1ef9f971620532d77799e2cce9f3e205034bfb792a

See more details on using hashes here.

File details

Details for the file django_paranoid-1.0-py3-none-any.whl.

File metadata

  • Download URL: django_paranoid-1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for django_paranoid-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bc8650bf0fab8f09c52bdc499264a4e1aaa6f60a495f82a8606276bdf135a84
MD5 5e53c2f2730c61a9d63c62d8c44c48d3
BLAKE2b-256 b9a3c80c4d33297958aed6a90ef314c8f4dda2bff5271b9273c8877c85093edd

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page