Created
April 16, 2012 17:04
-
-
Save dangerangell/2399980 to your computer and use it in GitHub Desktop.
api
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.resources import ModelResource, ALL, ALL_WITH_RELATIONS | |
from tastypie import fields | |
from saas.models import Event, Environment, Job, Customer, Product | |
class ProductResource(ModelResource): | |
class Meta: | |
queryset = Product.objects.all() | |
resource_name = 'product' | |
allowed_methods = ['get'] | |
excludes = ['created_at','updated_at'] | |
filtering = { | |
'alias': ALL | |
} | |
class CustomerResource(ModelResource): | |
class Meta: | |
queryset = Customer.objects.all() | |
resource_name = 'customer' | |
allowed_methods = ['get'] | |
excludes = ['created_at','updated_at'] | |
class JobResource(ModelResource): | |
product = fields.ForeignKey(ProductResource, 'product') | |
class Meta: | |
queryset = Job.objects.all() | |
resource_name = 'job' | |
allowed_methods = ['get'] | |
excludes = ['created_at','updated_at'] | |
filtering = { | |
'product' = ALL_WITH_RELATIONS | |
} | |
class EnvironmentResource(ModelResource): | |
class Meta: | |
queryset = Environment.objects.all() | |
resource_name = 'environment' | |
allowed_methods = ['get'] | |
excludes = ['created_at','updated_at'] | |
class EventResource(ModelResource): | |
environment = fields.ForeignKey(EnvironmentResource, 'environment',full=True) | |
job = fields.ForeignKey(JobResource, 'job',full=True) | |
class Meta: | |
queryset = Event.objects.all() | |
resource_name = 'event' | |
allowed_methods = ['get'] | |
excludes = ['created_at','updated_at'] | |
filtering = { | |
'job' = ALL_WITH_RELATIONS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment