Files
bugsink/bsmain/models.py
Klaas van Schelven 5895253803 Count view: async slow counts
when you count, it's usually because there are many, so this
extra complication is probaly going to be required
2025-04-17 22:03:23 +02:00

33 lines
1018 B
Python

import secrets
from django.db import models
from django.core.validators import RegexValidator
def generate_token():
# nchars = nbytes * 2
return secrets.token_hex(nbytes=20)
class AuthToken(models.Model):
"""Global (Bugsink-wide) token for authentication."""
token = models.CharField(max_length=40, unique=True, default=generate_token, validators=[
RegexValidator(regex=r'^[a-f0-9]{40}$', message='Token must be a 40-character hexadecimal string.'),
])
created_at = models.DateTimeField(auto_now_add=True, editable=False)
def __str__(self):
return f"AuthToken(token={self.token})"
class CachedModelCount(models.Model):
"""Model to cache the count of a specific model."""
app_label = models.CharField(max_length=255)
model_name = models.CharField(max_length=255)
count = models.PositiveIntegerField(null=False, blank=False)
last_updated = models.DateTimeField(auto_now=True)
class Meta:
unique_together = ('app_label', 'model_name')