๐Ÿ› Software ยท LARZ-401 · Session 2 of 8

Listings & the Data Model

Model seller-owned listings with the Larz ORM and render a simple catalog.

⏱ 10 min read📅 Updated 2026-07-25📊 Code examples throughout

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 seller field is the payout identity used later.
  • Store money as integer cents โ€” never floats.
  • The ORM auto-creates the table and migrates new columns.

More in this course

Course home → · Browse all courses →