As someone who never heard of Peewee until ten minutes ago, take this with a grain of salt:
from datetime import date
from peewee import *
class DrinksModel(Model):
class Meta:
database = SqliteDatabase('drinks.db')
class Order(DrinksModel):
id = PrimaryKeyField()
product = CharField()
user = CharField()
amount = IntegerField()
price = DecimalField()
date = DateField()
def get_orders_since(year, month=1, day=1):
orders = Order.select().where(Order.date >= date(year, month, day))
for order in get_orders_since(2014, 2, 14):
print(
"{}: {} drank {} x {}"
.format(order.date, order.user, order.amount, order.product)
)
If this gives an error, let me know what it says and we'll go from there.
Suggested changes:
The
user
field should probably become a foreign key into a User tableThe
product
field should become a foreign key into a Product table, and theprice
field should go into the Product table