mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Merge pull request #61 from jjkester/flush-command
Add command for purging the logs
This commit is contained in:
commit
4d5f394fae
5 changed files with 44 additions and 0 deletions
|
|
@ -121,3 +121,17 @@ related objects::
|
|||
obj = MyModel.objects.first()
|
||||
rel_history = LogEntry.objects.get_for_objects(obj.related.all())
|
||||
full_history = (obj.history.all() | rel_history.all()).order_by('-timestamp')
|
||||
|
||||
Management commands
|
||||
-------------------
|
||||
|
||||
.. versionadded:: 0.4.0
|
||||
|
||||
Auditlog provides the ``auditlogflush`` management command to clear all log entries from the database.
|
||||
|
||||
The command asks for confirmation, it is not possible to execute the command without giving any form of (simulated) user
|
||||
input.
|
||||
|
||||
.. warning::
|
||||
|
||||
Using the ``auditlogflush`` command deletes all log entries permanently and irreversibly from the database.
|
||||
|
|
|
|||
0
src/auditlog/management/__init__.py
Normal file
0
src/auditlog/management/__init__.py
Normal file
0
src/auditlog/management/commands/__init__.py
Normal file
0
src/auditlog/management/commands/__init__.py
Normal file
20
src/auditlog/management/commands/auditlogflush.py
Normal file
20
src/auditlog/management/commands/auditlogflush.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from django.core.management.base import NoArgsCommand
|
||||
from six import moves
|
||||
|
||||
from auditlog.models import LogEntry
|
||||
|
||||
|
||||
class Command(NoArgsCommand):
|
||||
help = 'Deletes all log entries from the database.'
|
||||
|
||||
def handle_noargs(self, **options):
|
||||
answer = None
|
||||
|
||||
while answer not in ['', 'y', 'n']:
|
||||
answer = moves.input("Are you sure? [y/N]: ").lower().strip()
|
||||
|
||||
if answer == 'y':
|
||||
count = LogEntry.objects.all().count()
|
||||
LogEntry.objects.all().delete()
|
||||
|
||||
print("Deleted %d objects." % count)
|
||||
10
src/auditlog_tests/manage.py
Normal file
10
src/auditlog_tests/manage.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "auditlog_tests.test_settings")
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
Loading…
Reference in a new issue