tastypie - Tasty pie search -
i have 2 models
class business(basetable): name = models.charfield(max_length=120) slug = models.slugfield(max_length=150) logo=models.onetoonefield("businesslogo",null=true,on_delete=models.set_null) class address(models.model): business = models.foreignkey("business", related_name='biz_address') address1 = models.charfield(max_length=100,null=true) address2 = models.charfield(max_length=100,null=true) state = models.foreignkey(states,null=true,on_delete=models.set_null) city = models.foreignkey(city,null=true,on_delete=models.set_null)
view.py
class businessresource(modelresource): class meta: queryset = business.objects.filter(status='p').order_by('-id') resource_name = 'business' filtering = { 'is_black_business': all, 'city': all_with_relations, } def dehydrate(self,bundle): if buss_address.city:bundle.data['city'] = buss_address.city.name else:bundle.data['city'] = '' // getting city here
problem need filter business using city .. how can ? guess
class businessresource(modelresource): addresses = fields.tomanyfield(addressresource, 'biz_address') class meta: filtering = { 'addresses': all_with_relations, } class addressresource(modelresource): city = fields.toonefield(cityresource, 'city') class meta: filtering = { 'city': all_with_relations, }
second way write custom filter overriding build_filters , apply_filters methods.
tastypie
No comments:
Post a Comment