def get_extra_subs_by_type(subscriptions, es_type): if isinstance(subscriptions, Subscription): # case 1: single subscription object is passed es = subscriptions.extra_subscription_set else: # case 2: queryset of subscriptions is passed es = ExtraSubscription.objects.filter( main_subscription__in=subscriptions) return es.filter(type=es_type).filter(q_isactive())
def get_types_by_size(subscriptions, size): if isinstance(subscriptions, Subscription): # case 1: single subscription object is passed parts = subscriptions.active_parts else: # case 2: queryset of subscriptions is passed parts = SubscriptionPart.objects.filter( subscription__in=subscriptions).filter(q_isactive()) return parts.filter(type__size=size)
def product_totals(self): products = Product.objects.all().order_by('code') amount_of_product = {} for product in products: productAmount = \ self.subscription_set.filter(q_isactive(), content__products__product__id=product.id).order_by('primary_member__first_name', 'primary_member__last_name').aggregate( Sum('content__products__amount'))['content__products__amount__sum'] or 0 amount_of_product[product] = productAmount return amount_of_product
def indexes(request): active_parts = SubscriptionPart.objects.filter( type__size__product__is_extra=False).filter(q_isactive()).filter( subscription__in=SubscriptionDao().all_active_subscritions()) types = SubscriptionTypeDao.get_all().filter( subscription_parts__in=active_parts).annotate( num=Count('id')).order_by('-price') renderdict = dict( subscription_types=types, average_sub_price=active_parts.aggregate( avg=Avg('type__price'))['avg'], average_paid_sub_price=active_parts.filter( type__price__gt=0).aggregate(avg=Avg('type__price'))['avg'], ) return render(request, 'mag/stats/indexes.html', renderdict)
def all_active_subscritions(): return Subscription.objects.filter(q_isactive())
def active_subscritions_by_depot(depot): return Subscription.objects.filter(depot=depot).filter(q_isactive())
def active_subscriptions(self): return self.subscription_set.filter(q_isactive()).order_by('primary_member__first_name', 'primary_member__last_name')
def extra_subscriptions(self): return self.extra_subscription_set.filter(q_isactive())
def active_parts(self): return self.parts.filter(q_isactive())
def all_active_extrasubscritions(): return ExtraSubscription.objects.filter(q_isactive())