implementation of read-only api for Work, Edition, Subject, Campaign, Author

added a check_db command to check database integrity of regluit.core.models
pull/1/head
Raymond Yee 2011-09-12 14:50:29 -07:00
parent 5deea69e6d
commit b24d315f19
3 changed files with 35 additions and 4 deletions

View File

@ -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'
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'

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

12
urls.py
View File

@ -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')),
)