def _create_deals(self): ads = Ad.objects.all() for i in range(10): ad = random.choice(ads) while True: try: creator_user = random.choice(self.users) amount = random.randint(1,ad.amount) factor = random.uniform(0.85, 1.15) unit_price = float(ad.price) * factor bid = unit_price * amount bid = Decimal(bid).quantize(Decimal('.00')) deal = Deal( ad=ad, creator=creator_user.get_userprofile(), owner=creator_user.get_business_profile(), bid=bid, currency=ad.currency, amount=amount ) deal.save() except IntegrityError: continue break self.deals = Deal.objects.all()
d.payed_to_agent = int(is_payed_to_agent) d.agent_commission = agent_commission d.cancel_reason = reason d.price = end_price if not bid: bid = 0.00 d.bid = bid if not amount: amount = 0 d.amount = amount #d.currency = sek_currency #d.commission_currency = sek_currency #d.agent_currency = sek_currency try: d.save(using=database) except IntegrityError: dd = Deal.objects.get(owner=business_profile, ad=ad) print "[ERROR] Unique conflict: Owner: %s for ad: %s" % (dd.owner, ad.pk) except csv.Error, e: exit('file %s, line %d: %s' % (filename, reader.line_num, e)) print "%s Deals" % (num2, ) num += num2 elif import_type == 'test': print ts_to_datetime(1337766315) num = 0 else: raise CommandError('Invalid import type. :/')