mirror of
https://github.com/coleifer/peewee.git
synced 2026-05-06 07:56:41 -04:00
Add query example model definitions
[skip ci]
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
# Collection of Query Examples.
|
||||
# https://docs.peewee-orm.com/en/latest/peewee/query_library.html
|
||||
|
||||
from functools import partial
|
||||
from peewee import *
|
||||
|
||||
|
||||
db = PostgresqlDatabase('peewee_clubdata')
|
||||
|
||||
class BaseModel(Model):
|
||||
class Meta:
|
||||
database = db
|
||||
|
||||
class Member(BaseModel):
|
||||
memid = AutoField() # Auto-incrementing primary key.
|
||||
surname = CharField()
|
||||
firstname = CharField()
|
||||
address = CharField(max_length=300)
|
||||
zipcode = IntegerField()
|
||||
telephone = CharField()
|
||||
recommendedby = ForeignKeyField('self', backref='recommended',
|
||||
column_name='recommendedby', null=True)
|
||||
joindate = DateTimeField()
|
||||
|
||||
class Meta:
|
||||
table_name = 'members'
|
||||
|
||||
|
||||
# Conveniently declare decimal fields suitable for storing currency.
|
||||
MoneyField = partial(DecimalField, decimal_places=2)
|
||||
|
||||
|
||||
class Facility(BaseModel):
|
||||
facid = AutoField()
|
||||
name = CharField()
|
||||
membercost = MoneyField()
|
||||
guestcost = MoneyField()
|
||||
initialoutlay = MoneyField()
|
||||
monthlymaintenance = MoneyField()
|
||||
|
||||
class Meta:
|
||||
table_name = 'facilities'
|
||||
|
||||
|
||||
class Booking(BaseModel):
|
||||
bookid = AutoField()
|
||||
facility = ForeignKeyField(Facility, column_name='facid')
|
||||
member = ForeignKeyField(Member, column_name='memid')
|
||||
starttime = DateTimeField()
|
||||
slots = IntegerField()
|
||||
|
||||
class Meta:
|
||||
table_name = 'bookings'
|
||||
Reference in New Issue
Block a user