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):
|
|
|
|
foo = models.BooleanField()
|
|
|
|
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-02 01:37:51 +03:00
|
|
|
return ('modelresourceexample.views.MyModelResource', (self.pk,))
|
2011-01-30 21:30:39 +03:00
|
|
|
|