mirror of
https://github.com/Crocmagnon/checkout.git
synced 2024-11-22 16:18:03 +01:00
Update dummy baskets generation to make it look more realistic
This commit is contained in:
parent
de3d7e4058
commit
7f90eb9ec3
2 changed files with 45 additions and 8 deletions
|
@ -14,33 +14,66 @@
|
||||||
"model": "purchase.product",
|
"model": "purchase.product",
|
||||||
"fields": {
|
"fields": {
|
||||||
"created_at": "2022-04-26T20:30:22.959Z",
|
"created_at": "2022-04-26T20:30:22.959Z",
|
||||||
"updated_at": "2022-04-26T20:30:22.959Z",
|
"updated_at": "2022-04-27T21:04:04.197Z",
|
||||||
"name": "Villard'Ain",
|
"name": "Villard'Ain",
|
||||||
"image": "",
|
"image": "",
|
||||||
"unit_price_cents": 290,
|
"unit_price_cents": 290,
|
||||||
"display_order": 1
|
"display_order": 2
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"model": "purchase.product",
|
"model": "purchase.product",
|
||||||
"fields": {
|
"fields": {
|
||||||
"created_at": "2022-04-26T20:30:22.959Z",
|
"created_at": "2022-04-26T20:30:22.959Z",
|
||||||
"updated_at": "2022-04-26T20:30:22.959Z",
|
"updated_at": "2022-04-28T16:09:00.142Z",
|
||||||
"name": "Herbier",
|
"name": "Herbier",
|
||||||
"image": "",
|
"image": "",
|
||||||
"unit_price_cents": 330,
|
"unit_price_cents": 330,
|
||||||
"display_order": 1
|
"display_order": 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"model": "purchase.product",
|
"model": "purchase.product",
|
||||||
"fields": {
|
"fields": {
|
||||||
"created_at": "2022-04-26T20:30:22.959Z",
|
"created_at": "2022-04-26T20:30:22.959Z",
|
||||||
"updated_at": "2022-04-26T20:30:22.959Z",
|
"updated_at": "2022-04-27T21:04:04.192Z",
|
||||||
"name": "Blanc vache",
|
"name": "Blanc vache",
|
||||||
"image": "",
|
"image": "",
|
||||||
"unit_price_cents": 650,
|
"unit_price_cents": 650,
|
||||||
"display_order": 1
|
"display_order": 3
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "purchase.product",
|
||||||
|
"fields": {
|
||||||
|
"created_at": "2022-04-28T16:08:08.298Z",
|
||||||
|
"updated_at": "2022-04-28T16:09:13.196Z",
|
||||||
|
"name": "Ap\u00e9rich\u00e8vres",
|
||||||
|
"image": "",
|
||||||
|
"unit_price_cents": 330,
|
||||||
|
"display_order": 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "purchase.product",
|
||||||
|
"fields": {
|
||||||
|
"created_at": "2022-04-28T16:08:16.542Z",
|
||||||
|
"updated_at": "2022-04-28T16:09:25.690Z",
|
||||||
|
"name": "Clougert",
|
||||||
|
"image": "",
|
||||||
|
"unit_price_cents": 450,
|
||||||
|
"display_order": 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "purchase.product",
|
||||||
|
"fields": {
|
||||||
|
"created_at": "2022-04-28T16:08:20.471Z",
|
||||||
|
"updated_at": "2022-04-28T16:09:34.003Z",
|
||||||
|
"name": "Brique",
|
||||||
|
"image": "",
|
||||||
|
"unit_price_cents": 290,
|
||||||
|
"display_order": 7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -32,13 +32,17 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def generate_baskets(self, payment_methods, products):
|
def generate_baskets(self, payment_methods, products):
|
||||||
count = int(random.normalvariate(20, 10))
|
count = int(random.normalvariate(20, 10))
|
||||||
|
methods_weights = [random.randint(1, 6) for _ in range(len(payment_methods))]
|
||||||
|
products_weights = [1 / product.display_order for product in products]
|
||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
method = random.choice(payment_methods)
|
method: PaymentMethod = random.choices(
|
||||||
|
payment_methods, weights=methods_weights
|
||||||
|
)[0]
|
||||||
basket = Basket.objects.create(payment_method=method)
|
basket = Basket.objects.create(payment_method=method)
|
||||||
items = []
|
items = []
|
||||||
item_count = int(random.normalvariate(3, 2))
|
item_count = int(random.normalvariate(3, 2))
|
||||||
for _ in range(item_count):
|
for _ in range(item_count):
|
||||||
product = random.choice(products)
|
product: Product = random.choices(products, weights=products_weights)[0]
|
||||||
items.append(
|
items.append(
|
||||||
BasketItem(
|
BasketItem(
|
||||||
product=product,
|
product=product,
|
||||||
|
|
Loading…
Reference in a new issue