Skip to content

Instantly share code, notes, and snippets.

@dangerangell
Created April 16, 2012 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangerangell/2399980 to your computer and use it in GitHub Desktop.
Save dangerangell/2399980 to your computer and use it in GitHub Desktop.
api
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