-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomClass.py
More file actions
69 lines (57 loc) · 1.6 KB
/
CustomClass.py
File metadata and controls
69 lines (57 loc) · 1.6 KB
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
import os
from peewee import PostgresqlDatabase
from peewee import AutoField
# Récupérer les variables d'environnement
DB_NAME = os.getenv('DB_NAME', 'api8inf349')
DB_USER = os.getenv('DB_USER', 'user')
DB_PASSWORD = os.getenv('DB_PASSWORD', 'pass')
DB_HOST = os.getenv('DB_HOST', 'localhost')
DB_PORT = int(os.getenv('DB_PORT', 5432))
db = PostgresqlDatabase(
DB_NAME,
user=DB_USER,
password=DB_PASSWORD,
host=DB_HOST,
port=DB_PORT
)
from peewee import (
Model,
IntegerField,
AutoField,
CharField,
DoubleField,
ForeignKeyField,
BooleanField
)
class Product(db.Model):
id = IntegerField(primary_key=True)
name = CharField()
type = CharField()
description = CharField()
image = CharField()
height = IntegerField()
weight = IntegerField()
price = DoubleField()
in_stock = BooleanField()
class Meta:
database = db
class Order(db.Model):
id = AutoField(primary_key=True)
email = CharField(null=True)
total_price = DoubleField(null=True)
total_price_tax = DoubleField(null=True)
credit_card = CharField(null=True)
shipping_information = CharField(null=True)
paid = BooleanField(null=True)
transaction = CharField(null=True)
shipping_price = DoubleField(null=True)
payment_status = CharField(null=True)
class Meta:
database = db
class ProductOrder(db.Model):
id = AutoField(primary_key=True)
order = ForeignKeyField(Order, backref='product_orders')
product = ForeignKeyField(Product, backref='orders')
quantity = IntegerField()
class Meta:
database = db