core: delete expired models when filtering instead of excluding them
closes #3233 Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
2432e51970
commit
9a9ba2560b
|
@ -482,8 +482,9 @@ class ExpiringModel(models.Model):
|
||||||
def filter_not_expired(cls, **kwargs) -> QuerySet:
|
def filter_not_expired(cls, **kwargs) -> QuerySet:
|
||||||
"""Filer for tokens which are not expired yet or are not expiring,
|
"""Filer for tokens which are not expired yet or are not expiring,
|
||||||
and match filters in `kwargs`"""
|
and match filters in `kwargs`"""
|
||||||
expired = Q(expires__lt=now(), expiring=True)
|
for obj in cls.objects.filter(**kwargs).filter(Q(expires__lt=now(), expiring=True)):
|
||||||
return cls.objects.exclude(expired).filter(**kwargs)
|
obj.delete()
|
||||||
|
return cls.objects.filter(**kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_expired(self) -> bool:
|
def is_expired(self) -> bool:
|
||||||
|
|
Reference in New Issue