Soft delete for MongoEngine
Project description
MongoEngine Soft Delete
Make a document soft deletable.
Installation
Install mongoengine-softdelete
through pip as usual:
pip install mongoengine-softdelete
Usage
Here is an example on how to use a soft deletable document:
from mongoengine_softdelete.document import SoftDeleteNoCacheDocument
class IceCream(SoftDeleteNoCacheDocument):
meta = {
'collection': 'ice_cream',
'soft_delete': {'deleted': True},
'indexes': [ 'flavor' ],
'strict': False
}
flavor = fields.StringField(required=True)
color = fields.StringField(required=True)
price = fields.FloatField(default=0)
created_at = fields.DateTimeField()
# Declare the field used to check if the record is soft deleted
# this field must also be reported in the `meta['soft_delete']` dict
deleted = fields.BooleanField(default=False)
# Save a new document
ice = IceCream(flavor="Vanilla", color="White").save()
assert not ice.is_soft_deleted
# Mark the document as soft deleted
ice.soft_delete()
assert len(IceCream.objects()) == 0
assert ice.is_soft_deleted
# Soft undelete the document
ice.soft_undelete()
assert len(IceCream.objects()) > 0
assert not ice.is_soft_deleted
Tests
The test suit requires that you run a local instance of MongoDB on the standard
port and have pytest
installed.
You can run tests with the pytest
command or with make test
.
Linting is done with mypy
and pycodestyle
with the make lint
command.
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
Close
Hashes for mongoengine-softdelete-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6114da848f23639b0eb5c26d16027381bb42dd18430efac0be28ea8b68a4cd8 |
|
MD5 | 3c35978d4c72b54bb73d5b7edfbf237a |
|
BLAKE2b-256 | bc98d686a06fcc237a5f3aee755ce24596e72445d57ee4ea57afa60edc444526 |
Close
Hashes for mongoengine_softdelete-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dba88c9df25c44bea8c545ba9c529c87c0309b2f826126932ad8be67284ddb1 |
|
MD5 | e7848943dcc0fa8ffe0b33f896ef4a5f |
|
BLAKE2b-256 | e96d80201869b07a069d39d402814b225153a51546931bdbf4d9a5a7c148bae4 |