-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
54 lines (35 loc) · 1.22 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from peewee import Model,CharField,AutoField,ForeignKeyField,TextField,IntegerField,SqliteDatabase,ManyToManyField
import os
cwd = os.getcwd()
db_path = os.path.join(cwd, "betsy.db")
db = SqliteDatabase(db_path)
class BaseModel(Model):
class Meta:
database = db
class Product(BaseModel):
name = CharField()
description = CharField()
price_in_cents = IntegerField()
class Tag(BaseModel):
name = CharField()
class User(BaseModel):
name = CharField()
adress = CharField()
billing_info = CharField()
class UserProduct(BaseModel):
user_id = ForeignKeyField(User, backref="products")
product_id = ForeignKeyField(Product, backref="owner")
stock = IntegerField(default=1)
class ProductTag(BaseModel):
product_id = ForeignKeyField(Product, backref="tags")
tag_id = ForeignKeyField(Tag)
class Transactions(BaseModel):
from_seller = ForeignKeyField(User, backref="Sold")
to_buyer = ForeignKeyField(User, backref='Bought')
product = ForeignKeyField(Product)
billing_info = TextField(null=True)
ammount = IntegerField()
class Meta:
indexes =(
(("from_seller", "to_buyer"), False),
)