aboutsummaryrefslogtreecommitdiffstats
path: root/examples/modelresourceexample/models.py
diff options
context:
space:
mode:
authortom christie tom@tomchristie.com2011-02-01 22:37:51 +0000
committertom christie tom@tomchristie.com2011-02-01 22:37:51 +0000
commit6ce5b643fbeab322d85dbaed87d11ffb950c5bed (patch)
treee08ad4cc8f465390564a3003daf8cf04b708438b /examples/modelresourceexample/models.py
parent196c21f37632e213702995651fd739426b6ee13a (diff)
downloaddjango-rest-framework-6ce5b643fbeab322d85dbaed87d11ffb950c5bed.tar.bz2
Added resourceexample, moved simpleexample to modelresourceexample
Diffstat (limited to 'examples/modelresourceexample/models.py')
-rw-r--r--examples/modelresourceexample/models.py23
1 files changed, 23 insertions, 0 deletions
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,))
+