Created
March 6, 2014 21:07
-
-
Save Elicia/9399650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.authorization import Authorization | |
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS | |
from tastypie import fields | |
from .models import Tema, Post, Capitulo | |
from apps.cursos.models import Curso, User | |
from apps.comentarios.apis import UserResource, CursoResource | |
class CapituloResource(ModelResource): | |
curso = fields.ForeignKey(CursoResource, 'curso', full=True) | |
autor = fields.ForeignKey(UserResource, 'autor', full=True) | |
class Meta: | |
queryset = Capitulo.objects.all() | |
resource_name = 'capitulo' | |
authorization = Authorization() | |
allowed_methods = ['get', 'post', 'delete', 'put'] | |
always_return_data = True | |
filtering = { | |
'slug': ALL, | |
'user': ALL_WITH_RELATIONS, | |
'created': ['exact', 'range', 'gt', 'gte', 'lt', 'lte'], | |
} | |
class TemaResource(ModelResource): | |
class Meta: | |
queryset = Tema.objects.all() | |
resource_name = 'temas' | |
class ArticuloResource(ModelResource): | |
tema = fields.ForeignKey(TemaResource, 'tema', null=True) | |
autor = fields.ForeignKey(UserResource, 'autor', full=True) | |
capitulo = fields.ForeignKey(CapituloResource, 'capitulo', blank=True, null=True) | |
class Meta: | |
queryset = Post.objects.exclude(capitulo_articulo__isnull=True) | |
resource_name = 'articulos' | |
authorization = Authorization() | |
allowed_methods = ['get', 'post', 'delete', 'put'] | |
always_return_data = True | |
class TutorialResource(ModelResource): | |
tema = fields.ForeignKey(TemaResource, 'tema', full=True, null=True) | |
autor = fields.ForeignKey(UserResource, 'autor', full=True) | |
capitulo = fields.ForeignKey(CapituloResource, 'capitulo', null=True, full=True) | |
class Meta: | |
queryset = Post.objects.exclude(tema_tutorial__isnull=True) | |
resource_name = 'tutoriales' | |
authorization = Authorization() | |
allowed_methods = ['get', 'post', 'delete', 'put'] | |
always_return_data = True | |
filtering = { | |
'slug': ALL, | |
'tema': ALL_WITH_RELATIONS, | |
'created': ['exact', 'range', 'gt', 'gte', 'lt', 'lte'], | |
} | |
/////////////// | |
from .apis import ArticuloResource, TutorialResource | |
art_resource = ArticuloResource() | |
tuto_resource = TutorialResource() | |
(r'^api/', include(art_resource.urls)), | |
(r'^api/', include(tuto_resource.urls)), | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment