blob: 4ab6f6e8aeed5a3262d4b6438654bc5d566f8356 [file] [log] [blame]
Siobhan Tullyce652d02013-10-08 21:52:35 -04001from django.db import models
2
3class SingletonModel(models.Model):
4 class Meta:
5 abstract = True
6
7 def save(self, *args, **kwargs):
8 self.__class__.objects.exclude(id=self.id).delete()
9 super(SingletonModel, self).save(*args, **kwargs)
10
11 @classmethod
12 def load(cls):
13 try:
14 return cls.objects.get()
15 except cls.DoesNotExist:
16 return cls()