dj11: replace deprecated symbols (#22682)
This commit is contained in:
parent
2db8756f48
commit
7846a6ab5b
|
@ -1,11 +1,11 @@
|
|||
from django.core.management.base import NoArgsCommand
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from fargo.fargo.utils import cleanup
|
||||
|
||||
|
||||
class Command(NoArgsCommand):
|
||||
class Command(BaseCommand):
|
||||
help = 'Clean expired models'
|
||||
|
||||
def handle_noargs(self, **options):
|
||||
def handle(self, *args, **options):
|
||||
cleanup()
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import hashlib
|
|||
|
||||
from django.utils.timezone import utc
|
||||
from django.utils.encoding import smart_bytes
|
||||
from django.db import models
|
||||
from django.apps import apps
|
||||
|
||||
try:
|
||||
import magic
|
||||
|
@ -42,6 +42,7 @@ def get_mime_type(path):
|
|||
mime_type = None
|
||||
return mime_type
|
||||
|
||||
|
||||
def cleanup_model(model, n=None):
|
||||
manager = getattr(model, 'objects', None)
|
||||
if hasattr(manager, 'cleanup'):
|
||||
|
@ -49,6 +50,5 @@ def cleanup_model(model, n=None):
|
|||
|
||||
|
||||
def cleanup(n=None):
|
||||
for app in models.get_apps():
|
||||
for model in models.get_models(app):
|
||||
cleanup_model(model, n=n)
|
||||
for model in apps.get_models():
|
||||
cleanup_model(model, n=n)
|
||||
|
|
Loading…
Reference in New Issue