aboutsummaryrefslogtreecommitdiffstats
path: root/examples/modelresourceexample/models.py
blob: ff0179c88ae1972cd0c921e2cb44fc63d1e83fe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from django.db import models

MAX_INSTANCES = 10

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)

    def save(self, *args, **kwargs):
        """
        For the purposes of the sandbox limit the maximum number of stored models.
        """
        super(MyModel, self).save(*args, **kwargs)
        while MyModel.objects.all().count() > MAX_INSTANCES:
            MyModel.objects.all().order_by('-created')[0].delete()