基于Django的轻量级软删除插件,支持Django>=1.11
Project description
Django-softdelete-new
基于Django的轻量级软删除插件,支持Django>=1.11。
快速开始
1、安装插件
pip install django-softdelete-new
2、导入基本Model
from soft_delete_new.models import SoftDeleteModel
3、将SoftDeleteModel类继承到模型类。它将添加以下功能:
objects的行为将发生以下变化:
返回所有非软删除的数据对象
delete() 方法将变成软删除方法。
hard_delete() 增加的方法,将数据真正从数据库中删除。
all_objects 是新增加的行为:
将始终返回软删除和非软删除的对象
only_deleted() 仅返回软删除对象的方法
undelete() 可以将all_objects返回的已经软删除的对象置为非软删除。
实例
from django.db import models
from soft_delete_it.models import SoftDeleteModel
class Author(SoftDeleteModel):
name = models.CharField(max_length=50)
dob = models.DateField()
class Article(SoftDeleteModel):
title = models.CharField(max_length=50)
body = models.TextField(null=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='articles')
Bob = Author.objects.create(name='bob', dob='2000-12-12')
John = Author.objects.create(name='john', dob='1990-10-12')
Author.objects.all() # return QuerySet with 2 objects
Bob.delete() # Bob is soft-deleted
Author.objects.all() # return QuerySet with 1 object, John
Author.all_objects.all() # return QuerySet with 2 object, Bob and John
Bob.undelete() # un-deletes Bob object
Author.objects.all() # return QuerySet with 2 objects
article1 = Article(title='Bob The Builder', body='')
article1.author = Bob
article1.save()
Article.objects.all() # return QuerySet with 1 object, article1
Bob.delete() # soft-deletes both Bob and article1 as Article's author field is on_delete_cascade and it Inherits SoftDeleteModel
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-softdelete-new-0.2.1.tar.gz.
File metadata
- Download URL: django-softdelete-new-0.2.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fd133857700fd6393989409b330f85dbfabdaeff73a9f29337b3e91e6219a2c
|
|
| MD5 |
51922e3724dab523a5f51c048e7d6589
|
|
| BLAKE2b-256 |
cbc77d943336e1ab1660be7b2aae36aad5dd9a917732d7a8e4326ed577698490
|
File details
Details for the file django_softdelete_new-0.2.1-py3-none-any.whl.
File metadata
- Download URL: django_softdelete_new-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8937c235ebb45dfecea0f859b7d0d27bde84daafc873c96f344f8ec9f3fb19f
|
|
| MD5 |
518e47992f79f50c2f4b5945807e4292
|
|
| BLAKE2b-256 |
415f3d0c8e0ca4e43908347eda43700b2535cea60c41b2d6b2d6526734280859
|