join-api/auth_app/models.py
2025-03-27 08:34:37 +01:00

15 lines
No EOL
522 B
Python

from django.utils import timezone
from rest_framework.authtoken.models import Token
from django.db import models
from join.settings import TOKEN_EXPIRATION_TIME
class ExpiringToken(Token):
expires_at = models.DateTimeField(null=True, blank=True)
def is_expired(self):
return self.expires_at and self.expires_at < timezone.now()
def save(self, *args, **kwargs):
if not self.expires_at:
self.expires_at = timezone.now() + TOKEN_EXPIRATION_TIME
super().save(*args, **kwargs)