Skip to content

Instantly share code, notes, and snippets.

@joejulian
Forked from mattdeboard/*scratch*.py
Last active December 21, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joejulian/6284688 to your computer and use it in GitHub Desktop.
Save joejulian/6284688 to your computer and use it in GitHub Desktop.
class Meta:
queryset = Item.objects.prefetch_related('components').all()
#...
def dehydrate_quantity(self, bundle):
if len(bundle.data['components']):
qty = min([ int(x.component.quantity/x.quantity) for x in bundle.obj.components.all() ] )
bundle.data['quantity'] = qty
return bundle.data['quantity']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment