Coverage for /home/tribaal/workspace/django-shop/shop/models/defaults/managers : 86.76%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
#============================================================================== # Product #============================================================================== """ A Manager for all the non-object manipulation needs, mostly statistics and other "data-mining" toys. """
""" This method "mines" the previously passed orders, and gets a list of products (of a size equal to the quantity parameter), ordered by how many times they have been purchased. """ # Importing here is fugly, but it saves us from circular imports... # Get an aggregate of product references and their respective counts 'product').annotate( product_count=Count('product') ).order_by('product_count' )[:quantity]
# The top_products_data result should be in the form: # [{'product_reference': '<product_id>', 'product_count': <count>}, ..]
# We could eventually return the count easily here, if needed.
""" A more classic manager for Product filtering and manipulation. """
#============================================================================== # Order #==============================================================================
""" Returns the last Order (from a time perspective) a given user has placed. """ if user and not isinstance(user, AnonymousUser): return self.filter(user=user).order_by('-modified')[0] else: return None
def create_from_cart(self, cart): """ This creates a new Order object (and all the rest) from a passed Cart object.
Specifically, it creates an Order with corresponding OrderItems and eventually corresponding ExtraPriceFields
This will only actually commit the transaction once the function exits to minimize useless database access.
Emits the ``processing`` signal. """ # must be imported here! ExtraOrderItemPriceField, ExtraOrderPriceField, OrderItem, ) # Let's create the Order itself:
# Let's serialize all the extra price arguments in DB
# There, now move on to the order items. # For each order item, we save the extra_price_fields to DB eoi = ExtraOrderItemPriceField() eoi.order_item = order_item # Force unicode, in case it has àö... eoi.label = unicode(label) eoi.value = value eoi.save()
|