An open API service indexing awesome lists of open source software.

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

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 TrackingFieldsMixin

class 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 SoftDeleteMixin

class 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 Model

class MyModel(Model):
mai_field = models.CharField()
other_field = models.BooleanField()
```