From 6ce5b643fbeab322d85dbaed87d11ffb950c5bed Mon Sep 17 00:00:00 2001 From: tom christie tom@tomchristie.com Date: Tue, 1 Feb 2011 22:37:51 +0000 Subject: Added resourceexample, moved simpleexample to modelresourceexample --- examples/modelresourceexample/models.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/modelresourceexample/models.py (limited to 'examples/modelresourceexample/models.py') diff --git a/examples/modelresourceexample/models.py b/examples/modelresourceexample/models.py new file mode 100644 index 00000000..036501d0 --- /dev/null +++ b/examples/modelresourceexample/models.py @@ -0,0 +1,23 @@ +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) + + class Meta: + ordering = ('created',) + + 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()[0].delete() + + @models.permalink + def get_absolute_url(self): + return ('modelresourceexample.views.MyModelResource', (self.pk,)) + -- cgit v1.2.3