-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
77 lines (59 loc) · 1.96 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# https://github.com/coleifer/peewee
from modules.peewee import *
import sys
sys.dont_write_bytecode = True
# can read database from external forces
db = SqliteDatabase('db.sqlite3')
class BaseModel(Model):
class Meta:
database = db
class Inventory_Invoice(BaseModel):
customer = CharField()
date = DateTimeField()
amount = IntegerField()
class Inventory_Product(BaseModel):
name = CharField()
description = CharField()
price = IntegerField(default=0)
class Inventory_InvoiceItem(BaseModel):
invoice = ForeignKeyField(Inventory_Invoice,backref='invoice_invoiceitems')
product = ForeignKeyField(Inventory_Product,backref='product_invoiceitems')
quantity = IntegerField()
class Users(BaseModel):
username = CharField()
password = CharField()
contact = IntegerField(default=0)
is_admin = CharField()
class Staff(BaseModel):
staffname = ForeignKeyField(Users,backref='users')
class States(BaseModel):
login = CharField()
admin = CharField()
def create_tables_if_not_exist():
if not Inventory_Product.table_exists():
db.create_tables([Inventory_Invoice, Inventory_Product, Inventory_InvoiceItem,Users,States],safe=True)
"""
Usage:
======
delete
------
item = Product.get(Product.id == self.mlb.item_selected[1])
item.delete_instance()
query
-----
p = Product.select()
p = Product.select().where(Product.name.contains(fnd)
p = Product.select().where(Product.name.contains(val)).order_by(Product.name)
items = InvoiceItem.select().where(InvoiceItem.invoice == 1)
for i in items: print (i.quantity,i.product.price)
create
------
cur_inv = Invoice.create(customer=inv[0],date=inv[1],amount=inv[2])
InvoiceItem.insert(invoice=cur_inv,product=i[0],quantity=i[1]).execute()
sample_products
---------------
f = open('product_sample.csv')
for i in range(10):
row = f.readline().rstrip().split(',')
Product.create(name=row[0],description=row[1],price=row[2])
"""