diff --git a/api/models.py b/api/models.py index be6c40d1..08a1bba0 100755 --- a/api/models.py +++ b/api/models.py @@ -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' \ No newline at end of file + 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' \ No newline at end of file diff --git a/api/urls.py b/api/urls.py index 218bc5ba..9b1dff6d 100644 --- a/api/urls.py +++ b/api/urls.py @@ -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)), ) diff --git a/urls.py b/urls.py index 1b5c55af..52727745 100755 --- a/urls.py +++ b/urls.py @@ -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')), - )