https://github.com/abdelhadi92/sitech-django-models
Django Soft Delete And Tracking Fields model
https://github.com/abdelhadi92/sitech-django-models
Last synced: 3 months ago
JSON representation
Django Soft Delete And Tracking Fields model
- Host: GitHub
- URL: https://github.com/abdelhadi92/sitech-django-models
- Owner: Abdelhadi92
- License: mit
- Created: 2019-11-14T00:25:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-14T00:25:33.000Z (over 5 years ago)
- Last Synced: 2025-01-18T00:14:42.357Z (5 months ago)
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Installation
Run the [pip](https://pip.pypa.io/en/stable/) command to install the latest version:
```bash
pip install git+https://github.com/sitmena/[email protected]
```## Usage
Given that you have the model
```python
class YourModel(models.Model):
mai_field = models.CharField()
other_field = models.BooleanField()
```
**-Tracking Fields:**
```python
from sitech_models import TrackingFieldsMixinclass YourModel(TrackingFieldsMixin, models.Model):
mai_field = models.CharField()
other_field = models.BooleanField()obj = YourModel.objects.get(1)
```
- Call `get_old_field('field_name')` to access the old value of a specific field.
- Call `set_old_field('field_name', value)` to set the old value of a specific field.
- Call `get_old_fields()` to access the old values.
- Call `get_dirty_fields()` to returns the fields names that have been modified since they are loaded or saved most recently.
**- Soft Delete:**
```python
from sitech_models import SoftDeleteMixinclass MyModel(SoftDeleteMixin, models.Model):
mai_field = models.CharField()
other_field = models.BooleanField()
obj = YourModel.objects.get(1)
```Add `SOFT_DELETE = True` to your `Settings`
- `obj.delete()` "soft delete"
- `YourModel.objects.filters().delete()` "soft delete"
- `YourModel.objects.filters().delete(force_delete=True)` "force delete"
- `obj.delete(force_delete=True)` "force delete"
**- Model:** You can use sitech_models.Model to exteneds all the above mixins
```python
from sitech_models import Modelclass MyModel(Model):
mai_field = models.CharField()
other_field = models.BooleanField()
```