django-rest-framework/examples/blogpost/views.py

28 lines
1.0 KiB
Python
Raw Normal View History

2011-05-02 22:49:12 +04:00
from djangorestframework.modelresource import InstanceModelResource, ListOrCreateModelResource
2011-02-19 13:47:26 +03:00
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')
2011-05-02 22:49:12 +04:00
class BlogPosts(ListOrCreateModelResource):
"""A resource with which lists all existing blog posts and creates new blog posts."""
model = models.BlogPost
fields = BLOG_POST_FIELDS
2011-04-27 21:53:54 +04:00
class BlogPostInstance(InstanceModelResource):
"""A resource which represents a single blog post."""
model = models.BlogPost
fields = BLOG_POST_FIELDS
2011-05-02 22:49:12 +04:00
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
2011-04-27 21:53:54 +04:00
class CommentInstance(InstanceModelResource):
"""A resource which represents a single comment."""
model = models.Comment
fields = COMMENT_FIELDS