2011-05-02 22:49:12 +04:00
|
|
|
from djangorestframework.modelresource import InstanceModelResource, ListOrCreateModelResource
|
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-01-24 02:08:16 +03:00
|
|
|
|
2011-05-02 22:49:12 +04:00
|
|
|
class BlogPosts(ListOrCreateModelResource):
|
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
|
|
|
model = models.BlogPost
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = BLOG_POST_FIELDS
|
|
|
|
|
2011-04-27 21:53:54 +04:00
|
|
|
class BlogPostInstance(InstanceModelResource):
|
2011-01-24 02:08:16 +03:00
|
|
|
"""A resource which represents a single blog post."""
|
2011-02-19 13:26:27 +03:00
|
|
|
model = models.BlogPost
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = BLOG_POST_FIELDS
|
|
|
|
|
2011-05-02 22:49:12 +04:00
|
|
|
class Comments(ListOrCreateModelResource):
|
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
|
|
|
model = models.Comment
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = COMMENT_FIELDS
|
|
|
|
|
2011-04-27 21:53:54 +04:00
|
|
|
class CommentInstance(InstanceModelResource):
|
2011-01-24 02:08:16 +03:00
|
|
|
"""A resource which represents a single comment."""
|
2011-02-19 13:26:27 +03:00
|
|
|
model = models.Comment
|
2011-01-24 02:08:16 +03:00
|
|
|
fields = COMMENT_FIELDS
|
|
|
|
|