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

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 = MyMode.objects_with_deleted.last()
m
<MyModel: name>
m.deleted_at
datetime.datetime(2019, 8, 10, 6, 16, 44, 633727, tzinfo=<UTC>)

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

django_paranoid-0.6-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_paranoid-0.6-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for django_paranoid-0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f602f38abe4c2552bcb291034d7681a1c69706b8ac40d23fdfe0f54c88afcdd8
MD5 5bdfe8cd070da0975661bca662000c3b
BLAKE2b-256 fb2f919a1e82d7528a16bd5fe079d9643225238306bb2dece4c96d82afbaaa9d

See more details on using hashes here.

Supported by

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