aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simpleexample/models.py
diff options
context:
space:
mode:
authortom christie tom@tomchristie.com2011-01-30 18:30:39 +0000
committertom christie tom@tomchristie.com2011-01-30 18:30:39 +0000
commit42f2f9b40d1295e18a5b720b0d1f6ad85e928d8a (patch)
tree458f97992bcd1348a413d21a5925f933ba7f74e3 /examples/simpleexample/models.py
parent8a470f031eeccf45625c3e3e18a8743021b38d41 (diff)
downloaddjango-rest-framework-42f2f9b40d1295e18a5b720b0d1f6ad85e928d8a.tar.bz2
Rename to django-rest-framework, get simpleexample working
Diffstat (limited to 'examples/simpleexample/models.py')
-rw-r--r--examples/simpleexample/models.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/simpleexample/models.py b/examples/simpleexample/models.py
new file mode 100644
index 00000000..13867f61
--- /dev/null
+++ b/examples/simpleexample/models.py
@@ -0,0 +1,23 @@
+from django.db import models
+
+MAX_INSTANCES = 20
+
+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."""
+ while MyModel.objects.all().count() > MAX_INSTANCES:
+ MyModel.objects.all()[0].delete()
+ super(MyModel, self).save(*args, **kwargs)
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('simpleexample.views.MyModelResource', (self.pk,))
+