BlogPosts > 10 rotation implemeneted

Latest Modelresource example is broken. Required attribute should be set to form, not model. Is fixed.
This commit is contained in:
markotibold 2011-03-06 13:26:19 +01:00
parent bba89cbcf1
commit 177e666fc2
3 changed files with 5 additions and 2 deletions

View File

@ -38,6 +38,9 @@ class BlogPost(models.Model):
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(self.__class__, self).save(*args, **kwargs)
for obj in self.__class__.objects.order_by('-pk')[10:]:
obj.delete()
class Comment(models.Model):

View File

@ -3,7 +3,7 @@ from django.db import models
MAX_INSTANCES = 10
class MyModel(models.Model):
foo = models.BooleanField(required=False)
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)

View File

@ -1,6 +1,6 @@
from django import forms
class MyForm(forms.Form):
foo = forms.BooleanField()
foo = forms.BooleanField(required=False)
bar = forms.IntegerField(help_text='Must be an integer.')
baz = forms.CharField(max_length=32, help_text='Free text. Max length 32 chars.')