Here is my Menu model:
class Menu(models.Model):
name = CharField(max_length=255)
shop = ForeignKey(Shop)
is_active = BooleanField(default=False)
What I need is, in ShopResource, ShopResource.menu returns only the active Menu object. Because there is always 1 active Menu object.
In ShopResource, I am trying:
def dehydrate(self, bundle):
bundle.data['menu'] = bundle.obj.menu_set.get(is_active=True)
return bundle
But ShopResource.menu is the string representation of the active menu object. I gues, I need to serialize something.
Any idea?
It’s a bit hard to figure out exactly what you need and what is your current situation because you haven’t provided any details of your Resources (i.e. source code of your Resources).
However I think that in order to get what you need you may want to specify the attribute parameter to be a callable like so:
This allows for filtering objects within the M2M relation.
Tastypie doesn’t say a lot (see Tastypie docs) but hopefully this will get you started.