mirror of
https://github.com/Crocmagnon/checkout.git
synced 2024-11-21 23:58:02 +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",
|
||||
"fields": {
|
||||
"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",
|
||||
"image": "",
|
||||
"unit_price_cents": 290,
|
||||
"display_order": 1
|
||||
"display_order": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "purchase.product",
|
||||
"fields": {
|
||||
"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",
|
||||
"image": "",
|
||||
"unit_price_cents": 330,
|
||||
"display_order": 1
|
||||
"display_order": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "purchase.product",
|
||||
"fields": {
|
||||
"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",
|
||||
"image": "",
|
||||
"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):
|
||||
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):
|
||||
method = random.choice(payment_methods)
|
||||
method: PaymentMethod = random.choices(
|
||||
payment_methods, weights=methods_weights
|
||||
)[0]
|
||||
basket = Basket.objects.create(payment_method=method)
|
||||
items = []
|
||||
item_count = int(random.normalvariate(3, 2))
|
||||
for _ in range(item_count):
|
||||
product = random.choice(products)
|
||||
product: Product = random.choices(products, weights=products_weights)[0]
|
||||
items.append(
|
||||
BasketItem(
|
||||
product=product,
|
||||
|
|
Loading…
Reference in a new issue