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
|
|
|
|
|
|
|
class MyModel(models.Model):
|
2011-03-03 12:02:41 +03:00
|
|
|
foo = models.BooleanField(required=False)
|
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)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('created',)
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
"""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:
|
|
|
|
MyModel.objects.all()[0].delete()
|
|
|
|
|
|
|
|
@models.permalink
|
|
|
|
def get_absolute_url(self):
|
2011-02-19 13:26:27 +03:00
|
|
|
return ('my-model-resource', (self.pk,))
|
2011-01-30 21:30:39 +03:00
|
|
|
|