diff --git a/api/models.py b/api/models.py index be1098cc..be6c40d1 100755 --- a/api/models.py +++ b/api/models.py @@ -1,7 +1,32 @@ from tastypie.resources import ModelResource +from tastypie import fields from regluit.core import models class WorkResource(ModelResource): class Meta: queryset = models.Work.objects.all() - resource_name = 'work' \ No newline at end of file + resource_name = 'work' + +class EditionResource(ModelResource): + work = fields.ForeignKey(WorkResource, 'work') + class Meta: + queryset = models.Edition.objects.all() + resource_name = 'edition' + +class CampaignResource(ModelResource): + work = fields.ForeignKey(WorkResource, 'work') + class Meta: + queryset = models.Campaign.objects.all() + resource_name = 'campaign' + +class AuthorResource(ModelResource): + works = fields.ToManyField(WorkResource, 'works') + class Meta: + queryset = models.Author.objects.all() + resource_name = 'author' + +class SubjectResource(ModelResource): + works = fields.ToManyField(WorkResource, 'works') + class Meta: + queryset = models.Subject.objects.all() + resource_name = 'subject' \ No newline at end of file diff --git a/docs/core_db_schema.png b/docs/core_db_schema.png index d1b782ff..65947672 100644 Binary files a/docs/core_db_schema.png and b/docs/core_db_schema.png differ diff --git a/urls.py b/urls.py index 43756a98..1b5c55af 100755 --- a/urls.py +++ b/urls.py @@ -1,14 +1,20 @@ from django.conf.urls.defaults import * -from regluit.api.models import WorkResource +from tastypie.api import Api +from regluit.api.models import WorkResource, EditionResource, CampaignResource, AuthorResource, SubjectResource -work_resource = WorkResource() +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(work_resource.urls)), + (r'^api/', include(v1_api.urls)), (r'', include('regluit.frontend.urls')), )