Add slug to order

This commit is contained in:
redfast00 2022-04-19 21:29:53 +02:00
parent 8350e57cc8
commit 563f9b84a2
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C

View file

@ -2,6 +2,8 @@
import typing
from datetime import datetime
from collections import defaultdict
import secrets
import string
from utils import first
from hlds.definitions import location_definitions
@ -18,9 +20,15 @@ class Order(db.Model):
starttime = db.Column(db.DateTime)
stoptime = db.Column(db.DateTime)
public = db.Column(db.Boolean, default=True)
slug = db.Column(db.String(7))
items = db.relationship("OrderItem", backref="order", lazy="dynamic")
def __init__(self):
super().__init__()
alphabet = string.ascii_letters + string.digits
self.slug = ''.join(secrets.choice(alphabet) for i in range(7))
def __getattr__(self, name):
if name == "location":
return first(