17 lines
548 B
Python
17 lines
548 B
Python
from django.core.management.base import BaseCommand, CommandError
|
|
from django.db import connection
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Remove old entries"
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument("--keep", type=int, default="100000")
|
|
|
|
def handle(self, *args, **options):
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(
|
|
"DELETE FROM mail_mail WHERE id not in (SELECT id FROM journal_entry ORDER BY timestamp desc LIMIT %s)",
|
|
[options['keep']],
|
|
)
|