Add management command for deleting all log entries

Issue #57
This commit is contained in:
Jan-Jelle Kester 2016-07-27 18:17:59 +02:00
parent e6f24cc78a
commit 81bcd47ab0
4 changed files with 30 additions and 0 deletions

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)