-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajoute une commande pour supprimer les vieilles adresses IP (#6608)
- Loading branch information
Showing
2 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
zds/utils/management/commands/remove_one_year_old_ip_addresses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from zds.utils.models import Comment | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Removes IP addresses that are more than one year old" | ||
|
||
def handle(self, *args, **options): | ||
one_year_ago = datetime.now() - timedelta(days=365) | ||
Comment.objects.filter(pubdate__lte=one_year_ago).exclude(ip_address="").update(ip_address="") | ||
self.stdout.write(self.style.SUCCESS(f"Successfully removed IP addresses that are more than one year old!")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters