Listings & the Data Model
Model seller-owned listings with the Larz ORM and render a simple catalog.
A listing belongs to a seller
from larz import Larz
from larz.models import Model, StrField, IntField, connect
app = Larz(secret="...")
connect("market.db")
class Listing(Model):
title = StrField()
seller = StrField(index=True) # e.g. "seller:alice"
price_cents = IntField(default=0)
image = StrField(default="")
Listing.create_table()List them
@app.get("/")
def home(req):
items = Listing.all(order="-id")
return "".join("<li>%s - $%.2f</li>" % (l.title, l.price_cents/100) for l in items)Takeaways
- The
sellerfield is the payout identity used later. - Store money as integer cents โ never floats.
- The ORM auto-creates the table and migrates new columns.