Merge pull request #61 from jjkester/flush-command

Add command for purging the logs
This commit is contained in:
Jan-Jelle Kester 2016-08-02 18:09:13 +02:00 committed by GitHub
commit 4d5f394fae
5 changed files with 44 additions and 0 deletions

View file

@ -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.

View file

View 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)

View 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)