Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
92 lines (70 sloc) 2.86 KB
from django.contrib.auth.models import User
from tastypie import fields
from tastypie.resources import ModelResource
from tastypie.authorization import Authorization
from core.models import Note
from related_resource.models import Category, Tag, ExtraData, Taggable, TaggableTag, GenericTag
class UserResource(ModelResource):
class Meta:
resource_name = 'users'
queryset = User.objects.all()
allowed_methods = ['get']
class NoteResource(ModelResource):
author = fields.ForeignKey(UserResource, 'author')
class Meta:
resource_name = 'notes'
queryset = Note.objects.all()
authorization = Authorization()
class CategoryResource(ModelResource):
parent = fields.ToOneField('self', 'parent', null=True)
tags = fields.ToManyField('related_resource.api.resources.GenericTagResource', attribute="tags", null=True, blank=True)
class Meta:
resource_name = 'category'
queryset = Category.objects.all()
authorization = Authorization()
class TagResource(ModelResource):
taggabletags = fields.ToManyField(
'related_resource.api.resources.TaggableTagResource', 'taggabletags',
null=True)
extradata = fields.ToOneField(
'related_resource.api.resources.ExtraDataResource', 'extradata',
null=True, blank=True, full=True)
class Meta:
resource_name = 'tag'
queryset = Tag.objects.all()
authorization = Authorization()
class TaggableResource(ModelResource):
taggabletags = fields.ToManyField(
'related_resource.api.resources.TaggableTagResource', 'taggabletags',
null=True)
class Meta:
resource_name = 'taggable'
queryset = Taggable.objects.all()
authorization = Authorization()
class TaggableTagResource(ModelResource):
tag = fields.ToOneField(
'related_resource.api.resources.TagResource', 'tag',
null=True)
taggable = fields.ToOneField(
'related_resource.api.resources.TaggableResource', 'taggable',
null=True)
class Meta:
resource_name = 'taggabletag'
queryset = TaggableTag.objects.all()
authorization = Authorization()
class ExtraDataResource(ModelResource):
tag = fields.ToOneField(
'related_resource.api.resources.TagResource', 'tag',
null=True)
class Meta:
resource_name = 'extradata'
queryset = ExtraData.objects.all()
authorization = Authorization()
class GenericTagResource(ModelResource):
content_type = fields.ContentTypeField()
content_object = fields.ToOneField(
{Category : CategoryResource, Taggable : TaggableResource}, attribute="content_object", contenttype_field=content_type)
class Meta:
resource_name = 'generictag'
queryset = GenericTag.objects.all()
authorization = Authorization()
Jump to Line
Something went wrong with that request. Please try again.