aboutsummaryrefslogtreecommitdiffstats
path: root/examples/blogpost
diff options
context:
space:
mode:
Diffstat (limited to 'examples/blogpost')
-rw-r--r--examples/blogpost/models.py8
-rw-r--r--examples/blogpost/urls.py13
-rw-r--r--examples/blogpost/views.py22
3 files changed, 22 insertions, 21 deletions
diff --git a/examples/blogpost/models.py b/examples/blogpost/models.py
index e1968415..c85ca788 100644
--- a/examples/blogpost/models.py
+++ b/examples/blogpost/models.py
@@ -24,13 +24,13 @@ class BlogPost(models.Model):
@models.permalink
def get_absolute_url(self):
- return ('blogpost.views.BlogPostInstance', (), {'key': self.key})
+ return ('blog-post', (), {'key': self.key})
@property
@models.permalink
def comments_url(self):
"""Link to a resource which lists all comments for this blog post."""
- return ('blogpost.views.CommentRoot', (), {'blogpost_id': self.key})
+ return ('comments', (), {'blogpost_id': self.key})
def __unicode__(self):
return self.title
@@ -52,11 +52,11 @@ class Comment(models.Model):
@models.permalink
def get_absolute_url(self):
- return ('blogpost.views.CommentInstance', (), {'blogpost': self.blogpost.key, 'id': self.id})
+ return ('comment', (), {'blogpost': self.blogpost.key, 'id': self.id})
@property
@models.permalink
def blogpost_url(self):
"""Link to the blog post resource which this comment corresponds to."""
- return ('blogpost.views.BlogPostInstance', (), {'key': self.blogpost.key})
+ return ('blog-post', (), {'key': self.blogpost.key})
diff --git a/examples/blogpost/urls.py b/examples/blogpost/urls.py
index ee209b3e..b2df96a1 100644
--- a/examples/blogpost/urls.py
+++ b/examples/blogpost/urls.py
@@ -1,8 +1,9 @@
-from django.conf.urls.defaults import patterns
+from django.conf.urls.defaults import patterns, url
+from blogpost.views import BlogPosts, BlogPostInstance, Comments, CommentInstance
-urlpatterns = patterns('blogpost.views',
- (r'^$', 'BlogPostRoot'),
- (r'^(?P<key>[^/]+)/$', 'BlogPostInstance'),
- (r'^(?P<blogpost_id>[^/]+)/comments/$', 'CommentRoot'),
- (r'^(?P<blogpost>[^/]+)/comments/(?P<id>[^/]+)/$', 'CommentInstance'),
+urlpatterns = patterns('',
+ url(r'^$', BlogPosts.as_view(), name='blog-posts'),
+ url(r'^(?P<key>[^/]+)/$', BlogPostInstance.as_view(), name='blog-post'),
+ url(r'^(?P<blogpost_id>[^/]+)/comments/$', Comments.as_view(), name='comments'),
+ url(r'^(?P<blogpost>[^/]+)/comments/(?P<id>[^/]+)/$', CommentInstance.as_view(), name='comment'),
)
diff --git a/examples/blogpost/views.py b/examples/blogpost/views.py
index bfb53b5d..0377b447 100644
--- a/examples/blogpost/views.py
+++ b/examples/blogpost/views.py
@@ -1,33 +1,33 @@
from djangorestframework.response import Response, status
from djangorestframework.resource import Resource
from djangorestframework.modelresource import ModelResource, RootModelResource
-from blogpost.models import BlogPost, Comment
+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')
-class BlogPostRoot(RootModelResource):
+class BlogPosts(RootModelResource):
"""A resource with which lists all existing blog posts and creates new blog posts."""
- allowed_methods = ('GET', 'POST',)
- model = BlogPost
+ anon_allowed_methods = allowed_methods = ('GET', 'POST',)
+ model = models.BlogPost
fields = BLOG_POST_FIELDS
class BlogPostInstance(ModelResource):
"""A resource which represents a single blog post."""
- allowed_methods = ('GET', 'PUT', 'DELETE')
- model = BlogPost
+ anon_allowed_methods = allowed_methods = ('GET', 'PUT', 'DELETE')
+ model = models.BlogPost
fields = BLOG_POST_FIELDS
-class CommentRoot(RootModelResource):
+class Comments(RootModelResource):
"""A resource which lists all existing comments for a given blog post, and creates new blog comments for a given blog post."""
- allowed_methods = ('GET', 'POST',)
- model = Comment
+ anon_allowed_methods = allowed_methods = ('GET', 'POST',)
+ model = models.Comment
fields = COMMENT_FIELDS
class CommentInstance(ModelResource):
"""A resource which represents a single comment."""
- allowed_methods = ('GET', 'PUT', 'DELETE')
- model = Comment
+ anon_allowed_methods = allowed_methods = ('GET', 'PUT', 'DELETE')
+ model = models.Comment
fields = COMMENT_FIELDS