2011-01-30 21:30:39 +03:00
|
|
|
from django.db import models
|
|
|
|
|
2011-01-31 11:41:21 +03:00
|
|
|
MAX_INSTANCES = 10
|
2011-01-30 21:30:39 +03:00
|
|
|
|
2012-02-23 12:58:10 +04:00
|
|
|
|
2011-01-30 21:30:39 +03:00
|
|
|
class MyModel(models.Model):
|
2011-03-06 15:26:19 +03:00
|
|
|
foo = models.BooleanField()
|
2011-01-30 21:30:39 +03:00
|
|
|
bar = models.IntegerField(help_text='Must be an integer.')
|
|
|
|
baz = models.CharField(max_length=32, help_text='Free text. Max length 32 chars.')
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
2011-05-16 17:11:36 +04:00
|
|
|
"""
|
|
|
|
For the purposes of the sandbox limit the maximum number of stored models.
|
|
|
|
"""
|
2011-01-31 11:41:21 +03:00
|
|
|
super(MyModel, self).save(*args, **kwargs)
|
2011-01-30 21:30:39 +03:00
|
|
|
while MyModel.objects.all().count() > MAX_INSTANCES:
|
2011-05-16 17:11:36 +04:00
|
|
|
MyModel.objects.all().order_by('-created')[0].delete()
|