1234567891011121314151617181920212223 |
- # -*- coding: utf-8 -*-
- from __future__ import unicode_literals
- from django.core.management.base import BaseCommand, CommandError
- from django.db.models import Count
- from coin.offers.models import Offer, OfferSubscription
- BOLD_START = '\033[1m'
- BOLD_END = '\033[0m'
- class Command(BaseCommand):
- help = "Return subscription count for each offer type"
- def handle(self, *args, **options):
- offers = Offer.objects\
- .annotate(num_subscribtions=Count('offersubscription'))\
- .order_by('name')
- for offer in offers:
- self.stdout.write("{offer} offer has {count} subscriber(s)".format(
- offer=BOLD_START + offer.name + BOLD_END,
- count=BOLD_START + str(offer.num_subscribtions) + BOLD_END))
|