diff options
| author | Tom Christie | 2011-05-02 19:49:12 +0100 |
|---|---|---|
| committer | Tom Christie | 2011-05-02 19:49:12 +0100 |
| commit | 8756664e064a18afc4713d921c318cd968f18433 (patch) | |
| tree | 8eb4499900552963f88972d0853e68d05159295f /examples/blogpost | |
| parent | b358fbdbe9cbd4ce644c4b2c7b9b4cec0811e14e (diff) | |
| download | django-rest-framework-8756664e064a18afc4713d921c318cd968f18433.tar.bz2 | |
emitters -> renderers
Diffstat (limited to 'examples/blogpost')
| -rw-r--r-- | examples/blogpost/models.py | 5 | ||||
| -rw-r--r-- | examples/blogpost/views.py | 7 |
2 files changed, 7 insertions, 5 deletions
diff --git a/examples/blogpost/models.py b/examples/blogpost/models.py index 01a91e15..3489c596 100644 --- a/examples/blogpost/models.py +++ b/examples/blogpost/models.py @@ -12,6 +12,8 @@ RATING_CHOICES = ((0, 'Awful'), (3, 'Good'), (4, 'Excellent')) +MAX_POSTS = 10 + class BlogPost(models.Model): key = models.CharField(primary_key=True, max_length=64, default=uuid_str, editable=False) title = models.CharField(max_length=128) @@ -38,9 +40,10 @@ 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:]: + for obj in self.__class__.objects.order_by('-pk')[MAX_POSTS:]: obj.delete() + class Comment(models.Model): blogpost = models.ForeignKey(BlogPost, editable=False, related_name='comments') username = models.CharField(max_length=128) diff --git a/examples/blogpost/views.py b/examples/blogpost/views.py index e47f4a5b..c4b54f73 100644 --- a/examples/blogpost/views.py +++ b/examples/blogpost/views.py @@ -1,12 +1,11 @@ -from djangorestframework.modelresource import InstanceModelResource, RootModelResource +from djangorestframework.modelresource import InstanceModelResource, ListOrCreateModelResource from blogpost import models BLOG_POST_FIELDS = ('created', 'title', 'slug', 'content', 'absolute_url', 'comment_url', 'comments_url') COMMENT_FIELDS = ('username', 'comment', 'created', 'rating', 'absolute_url', 'blogpost_url') -MAX_POSTS = 10 -class BlogPosts(RootModelResource): +class BlogPosts(ListOrCreateModelResource): """A resource with which lists all existing blog posts and creates new blog posts.""" model = models.BlogPost fields = BLOG_POST_FIELDS @@ -16,7 +15,7 @@ class BlogPostInstance(InstanceModelResource): model = models.BlogPost fields = BLOG_POST_FIELDS -class Comments(RootModelResource): +class Comments(ListOrCreateModelResource): """A resource which lists all existing comments for a given blog post, and creates new blog comments for a given blog post.""" model = models.Comment fields = COMMENT_FIELDS |
