django-rest-framework/examples/modelresourceexample/models.py
markotibold 177e666fc2 BlogPosts > 10 rotation implemeneted
Latest Modelresource example is broken. Required attribute should be set to form, not model. Is fixed.
2011-03-06 13:26:19 +01:00

24 lines
764 B
Python

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 ('my-model-resource', (self.pk,))