Skip to content
Browse files

Merge pull request #6 from tswicegood/demo-api

Demo api
  • Loading branch information...
2 parents f078809 + f6cae44 commit da333b444117462cf6fcce3abb23021843ecea40 @dmclain dmclain committed Aug 18, 2011
View
0 project_template/apis/__init__.py
No changes.
View
8 project_template/apis/api.py
@@ -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())
View
19 project_template/apis/resources.py
@@ -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"
View
BIN project_template/demo/demo_database.sqlite3
Binary file not shown.
View
2,310 project_template/demo/fixtures/demo_data.json
1,190 additions, 1,120 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
26 project_template/fixtures/initial_data.json
@@ -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": []
+ }
}
]
View
13 project_template/urls/api.py
@@ -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)),
+)
View
4 project_template/urls/defaults.py
@@ -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.
Something went wrong with that request. Please try again.