read only api now includes Wishlist and User

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

View File

@ -1,6 +1,14 @@
from django.contrib.auth.models import User
from regluit.core import models
from tastypie.resources import ModelResource from tastypie.resources import ModelResource
from tastypie import fields from tastypie import fields
from regluit.core import models
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
fields = ['username', 'first_name', 'last_name']
class WorkResource(ModelResource): class WorkResource(ModelResource):
class Meta: class Meta:
@ -30,3 +38,16 @@ class SubjectResource(ModelResource):
class Meta: class Meta:
queryset = models.Subject.objects.all() 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 django.conf.urls.defaults import *
from tastypie.api import Api from tastypie.api import Api
from regluit.api import models
api = Api() from regluit.api.models import UserResource, WorkResource, EditionResource, CampaignResource, AuthorResource, SubjectResource, EditionCoverResource, WishlistResource
api.register(models.WorkResource())
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('', urlpatterns = patterns('',
# The normal jazz here... (r'^', include(v1_api.urls)),
(r'^api/', include(api.urls)),
) )

14
urls.py
View File

@ -1,20 +1,8 @@
from django.conf.urls.defaults import * 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('', urlpatterns = patterns('',
(r'^accounts/', include('registration.backends.default.urls')), (r'^accounts/', include('registration.backends.default.urls')),
(r'^socialauth/', include('social_auth.urls')), (r'^socialauth/', include('social_auth.urls')),
(r'^api/', include(v1_api.urls)), (r'^api/', include('regluit.api.urls')),
(r'', include('regluit.frontend.urls')), (r'', include('regluit.frontend.urls')),
) )