* Cache GlobalSetting, again
This commit is contained in:
parent
e8d94878c6
commit
0a31ff47b5
|
|
@ -8,11 +8,12 @@ from io import BytesIO
|
|||
from typing import Optional
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
from django.db import models
|
||||
from django.db.models import F, Case, When, DecimalField, Prefetch, Max, Q
|
||||
from django.db.models.functions import Ceil
|
||||
from django.db.models import F, Case, When, DecimalField, Prefetch, Max, Q, Subquery, OuterRef
|
||||
from django.db.models.functions import Ceil, Coalesce
|
||||
from django.db.models.lookups import GreaterThan
|
||||
from django.db.transaction import atomic
|
||||
from django.utils import timezone
|
||||
|
|
@ -45,13 +46,18 @@ class GlobalSettings(models.Model):
|
|||
self.id = 1
|
||||
self.__class__.objects.exclude(id=self.id).delete()
|
||||
super().save(*args, **kwargs)
|
||||
cache.set('global_settings', self)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'GlobalSettings <{self.id}>'
|
||||
|
||||
@classmethod
|
||||
def load(cls) -> 'GlobalSettings':
|
||||
obj = cache.get('global_settings')
|
||||
|
||||
if not obj:
|
||||
obj, _ = cls.objects.get_or_create(id=1)
|
||||
cache.set('global_settings', obj)
|
||||
return obj
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user