from django.conf.urls import patterns, include from core.tests.api import Api, NoteResource, UserResource api = Api() api.register(NoteResource()) api.register(UserResource()) urlpatterns = patterns('', (r'^api/', include(api.urls)), )
class SubjectResource(ModelResource): class Meta: resource_name = 'subjects' queryset = Subject.objects.all() class UserResource(ModelResource): class Meta: resource_name = 'user' queryset = User.objects.all() class CustomNoteResource(ModelResource): author = fields.ForeignKey(UserResource, 'author') subjects = fields.ManyToManyField(SubjectResource, 'subjects') class Meta: resource_name = 'notes' queryset = Note.objects.all() api = Api(api_name='v1') api.register(CustomNoteResource()) api.register(UserResource()) api.register(SubjectResource()) urlpatterns = [ url(r'^api/', include(api.urls)), ]
try: from django.conf.urls import patterns, include except ImportError: # Django < 1.4 from django.conf.urls.defaults import patterns, include from core.tests.api import Api, NoteResource, UserResource api = Api() api.register(NoteResource()) api.register(UserResource()) urlpatterns = patterns( '', (r'^api/', include(api.urls)), )
from django.conf.urls.defaults import * from tastypie import fields from tastypie.resources import Resource from core.tests.api import Api, NoteResource, UserResource, NoteRepresentation from core.tests.fields import UserRepresentation, SubjectRepresentation class SubjectResource(Resource): representation = SubjectRepresentation resource_name = 'subjects' class CustomNoteRepresentation(NoteRepresentation): author = fields.ForeignKey(UserRepresentation, 'author') subjects = fields.ManyToManyField(SubjectRepresentation, 'subjects') api = Api(api_name='v1') api.register(NoteResource(representation=CustomNoteRepresentation)) api.register(UserResource()) api.register(SubjectResource()) urlpatterns = patterns('', (r'^api/', include(api.urls)), )