read only api now includes Wishlist and User

pull/1/head
Raymond Yee 2011-09-12 15:44:20 -07:00
parent 0846bab210
commit d3485a8842
3 changed files with 37 additions and 21 deletions

View File

@ -1,7 +1,15 @@
from tastypie.resources import ModelResource
from tastypie import fields
from django.contrib.auth.models import User
from regluit.core import models
from tastypie.resources import ModelResource
from tastypie import fields
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
fields = ['username', 'first_name', 'last_name']
class WorkResource(ModelResource):
class Meta:
queryset = models.Work.objects.all()
@ -29,4 +37,17 @@ class SubjectResource(ModelResource):
works = fields.ToManyField(WorkResource, 'works')
class Meta:
queryset = models.Subject.objects.all()
resource_name = 'subject'
resource_name = 'subject'
class EditionCoverResource(ModelResource):
edition = fields.ForeignKey(EditionResource, 'edition')
class Meta:
queryset = models.EditionCover.objects.all()
resource_name = 'editioncover'
class WishlistResource(ModelResource):
# add a user
works = fields.ToManyField(WorkResource, 'works')
class Meta:
queryset = models.Wishlist.objects.all()
resource_name = 'wishlist'

View File

@ -1,11 +1,18 @@
from django.conf.urls.defaults import *
from tastypie.api import Api
from regluit.api import models
api = Api()
api.register(models.WorkResource())
from regluit.api.models import UserResource, WorkResource, EditionResource, CampaignResource, AuthorResource, SubjectResource, EditionCoverResource, WishlistResource
v1_api = Api(api_name='v1') # how set api_name to None so that we don't get URIs like /api/v1 but more like /api/ Don't think there is a way...
v1_api.register(UserResource())
v1_api.register(WorkResource())
v1_api.register(EditionResource())
v1_api.register(EditionCoverResource())
v1_api.register(CampaignResource())
v1_api.register(AuthorResource())
v1_api.register(SubjectResource())
v1_api.register(WishlistResource())
urlpatterns = patterns('',
# The normal jazz here...
(r'^api/', include(api.urls)),
(r'^', include(v1_api.urls)),
)

14
urls.py
View File

@ -1,20 +1,8 @@
from django.conf.urls.defaults import *
from tastypie.api import Api
from regluit.api.models import WorkResource, EditionResource, CampaignResource, AuthorResource, SubjectResource
v1_api = Api(api_name='v1') # how set api_name to None? Don't think there is a way...
v1_api.register(WorkResource())
v1_api.register(EditionResource())
v1_api.register(CampaignResource())
v1_api.register(AuthorResource())
v1_api.register(SubjectResource())
# (r'^api/', include('regluit.api.urls'))
urlpatterns = patterns('',
(r'^accounts/', include('registration.backends.default.urls')),
(r'^socialauth/', include('social_auth.urls')),
(r'^api/', include(v1_api.urls)),
(r'^api/', include('regluit.api.urls')),
(r'', include('regluit.frontend.urls')),
)