Permalink
Browse files

Merge pull request #6 from tswicegood/demo-api

Demo api
  • Loading branch information...
dmclain committed Aug 18, 2011
2 parents f078809 + f6cae44 commit da333b444117462cf6fcce3abb23021843ecea40
No changes.
@@ -0,0 +1,8 @@
+from tastypie.api import Api
+
+from .resources import ArticleResource
+from .resources import AuthorsResource
+
+v1_api = Api(api_name="v1")
+v1_api.register(ArticleResource())
+v1_api.register(AuthorsResource())
@@ -0,0 +1,19 @@
+from armstrong.apps.articles.models import Article
+from django.contrib.auth.models import User
+from tastypie import fields
+from tastypie.resources import ModelResource
+
+
+class AuthorsResource(ModelResource):
+ class Meta:
+ queryset = User.objects.filter(groups__name="Authors")
+ resource_name = "users/author"
+ excludes = ["email", "is_superuser", "password", ]
+
+
+class ArticleResource(ModelResource):
+ authors = fields.ToManyField(AuthorsResource, "authors")
+
+ class Meta:
+ queryset = Article.published.all()
+ resource_name = "articles/article"
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,20 +1,28 @@
[
{
- "pk": 1,
- "model": "arm_wells.welltype",
+ "pk": 1,
+ "model": "arm_wells.welltype",
"fields": {
- "slug": "front_page",
+ "slug": "front_page",
"title": "front_page"
}
- },
+ },
{
- "pk": 1,
- "model": "arm_wells.well",
+ "pk": 1,
+ "model": "arm_wells.well",
"fields": {
- "active": true,
- "pub_date": "2011-07-06 17:28:10",
- "expires": null,
+ "active": true,
+ "pub_date": "2011-07-06 17:28:10",
+ "expires": null,
"type": 1
}
+ },
+ {
+ "pk": 1,
+ "model": "auth.group",
+ "fields": {
+ "name": "Authors",
+ "permissions": []
+ }
}
]
@@ -0,0 +1,13 @@
+"""
+Contains URL patterns for a basic API using `Tastypie`_.
+
+.. _tastypie: https://github.com/toastdriven/django-tastypie
+"""
+from django.conf.urls.defaults import patterns, include, url
+
+from apis.api import v1_api
+
+
+urlpatterns = patterns('',
+ url(r'^api/', include(v1_api.urls)),
+)
@@ -58,3 +58,7 @@
},
name='article_detail'),
)
+
+# Uncomment the following two lines if you want to expose our default API
+# from .api import urlpatterns as api_urlpatterns
+# urlpatterns += api_urlpatterns

0 comments on commit da333b4

Please sign in to comment.