stuff is working again

This commit is contained in:
2025-06-26 05:21:21 -05:00
parent 7a8ec5face
commit 00fd49c79b
12 changed files with 639 additions and 272 deletions

View File

@ -82,6 +82,7 @@ class Plant(db.Model):
plant_type = db.Column(db.String(50), nullable=False)
notes = db.Column(db.Text, nullable=True)
short_id = db.Column(db.String(8), unique=True, nullable=True, index=True)
vendor_name = db.Column(db.String(255), nullable=True)
price = db.Column(db.Numeric(10, 2), nullable=True)
@ -151,3 +152,16 @@ class Plant(db.Model):
def __repr__(self):
return f"<Plant {self.uuid} ({self.plant_type})>"
@classmethod
def generate_short_id(cls, length: int = 6) -> str:
"""
Produce a random [az09] string of the given length
and ensure it doesnt collide with any existing plant.short_id.
"""
alphabet = string.ascii_lowercase + string.digits
while True:
candidate = ''.join(random.choices(alphabet, k=length))
# Check uniqueness
if not cls.query.filter_by(short_id=candidate).first():
return candidate