Metadata-Version: 2.1
Name: django-federation-auditlog
Version: 0.2.4
Summary: 
Author: Anderson Marques
Author-email: anderson89marques@gmail.com
Requires-Python: >=3.7,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: django-auditlog (==1.0.0)
Requires-Dist: djangorestframework (==3.11.1)
Requires-Dist: djangorestframework-simplejwt (==5.0.0)
Description-Content-Type: text/markdown

# Django Auditlog
This project is totally based in [Django Auditlog](https://github.com/jazzband/django-auditlog/tree/master) library.

# Instalation

with pip

```shell
pip install django-federation-auditlog
```

with pipenv

```shell
pipenv install django-federation-auditlog
```

with poetry

```shell
poetry django-federation-auditlog
```

# Adding Django Federation Auditlog to your Django application

To use in your application, just add 'django-federation-auditlog' to your project’s INSTALLED_APPS setting and add 'AuditlogMiddleware' to your's MIDDLEWARE setting then run manage.py migrate to create/upgrade the necessary database structure.

```python

INSTALLED_APPS = [
    # other apps
    "django_federation_auditlog",
]
```

and 

```python

MIDDLEWARE = [
    # others middlewares
    "django_federation_auditlog.middleware.AuditlogMiddleware",
]
```

Then run

```
python manage.py migrate
```

# Usage

Auditlog can automatically log changes to objects for you. This functionality is based on Django’s signals, but linking your models to Django Federation Auditlog is even easier using signals.

```python
from django.db import models

from django_federation_auditlog.registry import auditlog

class MyModel(models.Model):
    pass
    # Model definition goes here

auditlog.register(MyModel)
```

It is recommended to place the register code (auditlog.register(MyModel)) at the bottom of your models.py file.

## Including Fields

If ```include_fields``` is specified, only the fields with the given names will be included in the generated log entries.

For example, to include only the field ```name``` from class MyModel, use:

```python
from django.db import models

from django_federation_auditlog.registry import auditlog

class MyModel(models.Model):
    name = models.CharField()
    description = models.CharField()
    # Model definition goes here

auditlog.register(MyModel, include_fields=["name"])
```

## Excluding fields

Fields that are excluded will not trigger saving a new log entry and will not show up in the recorded changes.

If ```exclude_fields``` is specified the fields with the given names will not be included in the generated log entries.

For example, to exclude the field ```description```, use:

```python
from django.db import models

from django_federation_auditlog.registry import auditlog

class MyModel(models.Model):
    name = models.CharField()
    description = models.CharField()
    # Model definition goes here

auditlog.register(MyModel, exclude_fields=["description"])
```
