mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Change the way product refs are being generated.
Add a salt of randomness to avoid conflicts.
This commit is contained in:
parent
4d17e28dd2
commit
1c85f39c82
1 changed files with 5 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
|||
from datetime import datetime
|
||||
|
||||
import random
|
||||
import string
|
||||
|
||||
from slugify import slugify
|
||||
from .core import app
|
||||
from ..models import Delivery, Product, Producer
|
||||
|
@ -153,7 +156,8 @@ async def create_product(request, response, delivery_id, producer_id):
|
|||
product.producer = producer_id
|
||||
form = request.form
|
||||
product.update_from_form(form)
|
||||
product.ref = slugify(f"{producer_id}-{product.name}-{product.unit}")
|
||||
random_string = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
|
||||
product.ref = slugify(f"{producer_id}-{product.name}-{product.unit}-{random_string}")
|
||||
|
||||
delivery.products.append(product)
|
||||
delivery.persist()
|
||||
|
|
Loading…
Reference in a new issue