2011-01-30 21:30:39 +03:00
|
|
|
from djangorestframework.modelresource import ModelResource, RootModelResource
|
2011-02-19 13:47:26 +03:00
|
|
|
|
2011-02-19 13:26:27 +03:00
|
|
|
from blogpost import models
|
2011-01-24 02:08:16 +03:00
|
|
|
|
|
|
|
BLOG_POST_FIELDS = ('created', 'title', 'slug', 'content', 'absolute_url', 'comment_url', 'comments_url')
|
2011-01-30 14:00:20 +03:00
|
|
|
COMMENT_FIELDS = ('username', 'comment', 'created', 'rating', 'absolute_url', 'blogpost_url')
|
2011-03-11 14:47:16 +03:00
|
|
|
MAX_POSTS = 10
|
2011-01-24 02:08:16 +03:00
|
|
|
|
2011-02-19 13:26:27 +03:00
|
|
|
class BlogPosts(RootModelResource):
|
2011-01-30 14:00:20 +03:00
|
|
|
"""A resource with which lists all existing blog posts and creates new blog posts."""
|
2011-02-19 13:26:27 +03:00
|
|
|
anon_allowed_methods = allowed_methods = ('GET', 'POST',)
|
|
|
|
model = models.BlogPost
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = BLOG_POST_FIELDS
|
|
|
|
|
|
|
|
class BlogPostInstance(ModelResource):
|
|
|
|
"""A resource which represents a single blog post."""
|
2011-02-19 13:26:27 +03:00
|
|
|
anon_allowed_methods = allowed_methods = ('GET', 'PUT', 'DELETE')
|
|
|
|
model = models.BlogPost
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = BLOG_POST_FIELDS
|
|
|
|
|
2011-02-19 13:26:27 +03:00
|
|
|
class Comments(RootModelResource):
|
2011-01-30 14:00:20 +03:00
|
|
|
"""A resource which lists all existing comments for a given blog post, and creates new blog comments for a given blog post."""
|
2011-02-19 13:26:27 +03:00
|
|
|
anon_allowed_methods = allowed_methods = ('GET', 'POST',)
|
|
|
|
model = models.Comment
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = COMMENT_FIELDS
|
|
|
|
|
|
|
|
class CommentInstance(ModelResource):
|
|
|
|
"""A resource which represents a single comment."""
|
2011-02-19 13:26:27 +03:00
|
|
|
anon_allowed_methods = allowed_methods = ('GET', 'PUT', 'DELETE')
|
|
|
|
model = models.Comment
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = COMMENT_FIELDS
|
|
|
|
|