Django
- 1 ответ
- 0 вопросов
0
Вклад в тег
from django.db import models
class SingletonModel(models.Model):
"""Singleton model for global settings for example."""
class Meta:
abstract = True
def save(self, *args, **kwargs):
"""Save with id=1."""
self.pk = 1
super(SingletonModel, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
"""Can't delete by default."""
pass
@classmethod
def load(cls):
"""Load value from model."""
obj, created = cls.objects.get_or_create(pk=1)
return obj