Пример #1
0
def MarketMake(modeladmin,request,queryset):
	for p in queryset:
		market = Market(product = p, open_time = p.open_time, close_time = p.close_time,name = p.name, market_number = 1)
		market.save()
		pricehistory = PriceHistory(product = p, number = 1)
		pricehistory.save()
		securityprice = SecurityPrice(market = market)
		securityprice.save()
		for i in range(0,p.security_number):
			attributes = [""] * p.attribute_set.count()
			loop = True
			while loop:
				for att in p.attribute_set.all():
					rand = random.randint(0,(att.level_set.count()-1))
					level = att.level_set.get(number = rand)
					attributes[p.order[att.number]] = level.name
				try:
					test = Security.objects.get(market=market,attributes=attributes)
					attributes = [""] * p.attribute_set.count()
				except Security.DoesNotExist:
					name = ""
					for att_name in attributes:
						name = name + " " + att_name

					security = Security(market=market,number=i)
					security.attributes = attributes
					security.attribute_name = name
					security.save()
					loop = False
Пример #2
0
def MarketMake(modeladmin, request, queryset):
    for p in queryset:
        market = Market(product=p,
                        open_time=p.open_time,
                        close_time=p.close_time,
                        name=p.name,
                        market_number=1)
        market.save()
        pricehistory = PriceHistory(product=p, number=1)
        pricehistory.save()
        securityprice = SecurityPrice(market=market)
        securityprice.save()
        for i in range(0, p.security_number):
            attributes = [""] * p.attribute_set.count()
            loop = True
            while loop:
                for att in p.attribute_set.all():
                    rand = random.randint(0, (att.level_set.count() - 1))
                    level = att.level_set.get(number=rand)
                    attributes[p.order[att.number]] = level.name
                try:
                    test = Security.objects.get(market=market,
                                                attributes=attributes)
                    attributes = [""] * p.attribute_set.count()
                except Security.DoesNotExist:
                    name = ""
                    for att_name in attributes:
                        name = name + " " + att_name

                    security = Security(market=market, number=i)
                    security.attributes = attributes
                    security.attribute_name = name
                    security.save()
                    loop = False