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 hashes)

Uploaded source

Built Distribution

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

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page