core: fix logic error in expired models cleanup
This commit is contained in:
parent
683968c96e
commit
c7daadfb18
|
@ -1,4 +1,5 @@
|
||||||
"""passbook core tasks"""
|
"""passbook core tasks"""
|
||||||
|
from django.utils.timezone import now
|
||||||
from structlog import get_logger
|
from structlog import get_logger
|
||||||
|
|
||||||
from passbook.core.models import ExpiringModel
|
from passbook.core.models import ExpiringModel
|
||||||
|
@ -12,5 +13,10 @@ def clean_expired_models():
|
||||||
"""Remove expired objects"""
|
"""Remove expired objects"""
|
||||||
for cls in ExpiringModel.__subclasses__():
|
for cls in ExpiringModel.__subclasses__():
|
||||||
cls: ExpiringModel
|
cls: ExpiringModel
|
||||||
amount, _ = cls.filter_not_expired().delete()
|
amount, _ = (
|
||||||
|
cls.objects.all()
|
||||||
|
.exclude(expiring=False)
|
||||||
|
.exclude(expiring=True, expires__gt=now())
|
||||||
|
.delete()
|
||||||
|
)
|
||||||
LOGGER.debug("Deleted expired models", model=cls, amount=amount)
|
LOGGER.debug("Deleted expired models", model=cls, amount=amount)
|
||||||
|
|
Reference in a new issue