implementation of read-only api for Work, Edition, Subject, Campaign, Author
added a check_db command to check database integrity of regluit.core.modelspull/1/head
parent
5deea69e6d
commit
b24d315f19
|
@ -1,7 +1,32 @@
|
||||||
from tastypie.resources import ModelResource
|
from tastypie.resources import ModelResource
|
||||||
|
from tastypie import fields
|
||||||
from regluit.core import models
|
from regluit.core import models
|
||||||
|
|
||||||
class WorkResource(ModelResource):
|
class WorkResource(ModelResource):
|
||||||
class Meta:
|
class Meta:
|
||||||
queryset = models.Work.objects.all()
|
queryset = models.Work.objects.all()
|
||||||
resource_name = 'work'
|
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
12
urls.py
|
@ -1,14 +1,20 @@
|
||||||
from django.conf.urls.defaults import *
|
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'))
|
# (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(work_resource.urls)),
|
(r'^api/', include(v1_api.urls)),
|
||||||
(r'', include('regluit.frontend.urls')),
|
(r'', include('regluit.frontend.urls')),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue