Django Timestamps
Adds created_at, updated_at, and/or deleted_at (soft-delete) to django models
Usage
from django.db import models
from django_timestamps.softDeletion import SoftDeletionModel
from django_timestamps.timestamps import TimestampsModel
class Device(SoftDeletionModel, TimestampsModel):
name = models.CharField(max_length=20)
os = models.CharField(max_length=20)
TimestampsModel adds created_at and updated_at fields to the model. This fields are updated automatically
SoftDeletionModel adds deleted_at (soft-delete)
To soft-delete a model you must call delete() function:
device = Device.objects.filter(id=1).first()
device.delete()
To hard-delete a model you must call hard_delete() function:
device = Device.objects.filter(id=1).first()
device.hard_delete()
To restore a model you must call restore() function and use all_objects instead of objects:
device = Device.all_objects.filter(id=1).first()
device.restore()
To get all objects trashed
devices_trashed = Device.all_objects.all().dead()
ModelViewSet for rest_framework:
Adds urls for soft-deleted elements, returns deleted_at:
#Example for devices:
# (get) /devices/trashed/ -> trashed elements, paginated
# (get) /devices/4/get-trashed/ -> get trashed element
# (patch) /devices/4/restore/ -> restore trashed element
from django_timestamps.SoftDeleteViewSet import SoftDeleteViewSet
class DeviceViewSet(viewsets.ModelViewSet, SoftDeleteViewSet):
queryset = Device.objects.all().order_by('id')
serializer_class = DeviceSerializer
querysetTrashed = Device.all_objects.all().dead().order_by('id')
#add extra filters for queryset and querysetTrashed
def full_queryset(self, queryset):
user_id = self.request.query_params.get('user_id', None)
if user_id:
queryset = queryset.filter(user_id=user_id)
return queryset
Metadata
Release files for django-timestamps 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-timestamps-0.0.1.tar.gz | 2.8 kB | Without provenance | Details for django-timestamps-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_timestamps-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for django_timestamps-0.0.1-py3-none-any.whl |
Total release size: 7.8 kB
Release files / django-timestamps-0.0.1.tar.gz
| Download URL | django-timestamps-0.0.1.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21d2788a89c79c375e7ebd5c7d0a9b272528f9e7140d20a71dbc545be8fbf14d
|
|
BLAKE2b-256 checksum How to use checksums |
e287ed338a078149fcd3edcd0155bda0e2e1899c0fc7389a0b885308625123fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4
|
Release files / django_timestamps-0.0.1-py3-none-any.whl
| Download URL | django_timestamps-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd1e43d55149020fd3758ddd46109640c46a9ad0df3e2e5213ff5bf4c07d1050
|
|
BLAKE2b-256 checksum How to use checksums |
0baa981378666b473a23af5730cca8933b579f8967ea19efaaffe49ef8dca1e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4
|
Security for django-timestamps 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.