Last active
September 26, 2017 20:38
-
-
Save jordotech/355c4728f415b31e51b2821dd9957b7c to your computer and use it in GitHub Desktop.
pending_orderitem_options view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from product.modules.configurable.models import ConfigurableProduct, ProductVariation | |
from satchmo_store.shop.models import OrderItem | |
def pending_orderitem_options(request, product_id): | |
cp = ConfigurableProduct.objects.get(pk=product_id) # this is the url argument | |
child_ids = [v.product_id for v in cp.productvariation_set.all()] # find the cp's child product ids | |
orderitems = OrderItem.objects.filter(product_id__in=child_ids) # find the order items that match any of the children product ids | |
data = {} # The table in the view will be built from this dictionary | |
for oi in orderitems: # we step through the order items and build the needed data broken down by variation | |
v = ProductVariation.objects.get(pk=oi.product_id) | |
if v not in data: | |
data[v] = { | |
'orders': [oi.order], | |
'qty': oi.quantity, | |
} | |
else: | |
data[v]['orders'].append(oi.order) | |
data[v]['qty'] += oi.quantity | |
print data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment