Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dynamic model registration #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ ENV/
# Rope project settings
.ropeproject
.idea
.tm_properties

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Below are some of the settings you may want to use. These should be defined in y

A list of Django models which will be ignored by Django Easy Audit.
Use it to prevent logging one or more of your project's models.
List items can be classes or strings with `app_name.model_name` format.
List items can be classes, strings with `app_name.model_name` format or functions that will return classes.

* `DJANGO_EASY_AUDIT_UNREGISTERED_URLS_EXTRA`

Expand Down
5 changes: 4 additions & 1 deletion easyaudit/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from importlib import import_module
from inspect import isfunction

import django.db.utils
from django.apps import apps
Expand All @@ -23,6 +23,9 @@ def get_model_list(class_list):
if isinstance(item, (str,)):
model_class = apps.get_model(item)
class_list[idx] = model_class
elif isfunction(item):
model_class = item()
class_list[idx] = model_class


# Should Django Easy Audit log model/auth/request events?
Expand Down
12 changes: 12 additions & 0 deletions easyaudit/tests/test_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,15 @@
STATIC_URL = '/static/'

DJANGO_EASY_AUDIT_REQUEST_EVENT_LIST_FILTER = ['method', 'datetime', ]


def lazy_test_model():
from test_app.models import TestModel
return TestModel


DJANGO_EASY_AUDIT_REGISTERED_CLASSES = [
"test_app.TestM2M",
"test_app.TestForeignKey",
lazy_test_model,
]