鑑於以下API定義,我需要能夠按產品別名過濾事件。如何使用Tastypie通過相關模型屬性過濾API結果?
鑑於一個事件屬於一個工作,而一個工作屬於一個產品,我不確定如何規範。
api.py:
class ProductResource(ModelResource):
class Meta:
queryset = Product.objects.all()
resource_name = 'product'
allowed_methods = ['get']
excludes = ['created_at','updated_at']
filtering = {
'alias': ALL
}
class EnvironmentResource(ModelResource):
class Meta:
queryset = Environment.objects.all()
resource_name = 'environment'
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']
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 = {
HOW DO I FILTER BY PRODUCT ALIAS????
}
我怎麼看,應該工作,但我對在JobResource的產品過濾得到一個語法錯誤。 – 2012-04-16 14:49:24
或許你可以與我們分享錯誤訊息? – kgr 2012-04-16 15:11:46
'的SyntaxError在/ 無效的語法(api.py 34行) 請求方法:\t GET 請求URL:\t http://127.0.0.1:8000/ Django的版本:\t 1.3.1 異常類型:\t語法錯誤 異常值:\t 無效的語法(api.py,第34行)' – 2012-04-16 17:02:46