-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase_setup.py
38 lines (35 loc) · 1.13 KB
/
database_setup.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
import os
import sys
from sqlalchemy import Column,ForeignKey,Integer,String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
Base= declarative_base()
class Food(Base):
__tablename__='food'
id=Column(Integer,primary_key=True)
name=Column(String(20),nullable=False)
description=Column(String(300),nullable=False)
image=Column(String(250),nullable=False)
categories=Column(String(20),nullable=False)
place=Column(String(20))
price=Column(Integer)
@property
def serialize(self):
return {
'id': self.id,
'name': self.name,
'description': self.description,
'image': self.image,
'categories': self.categories
}
class User(Base):
__tablename__='User'
id=Column(Integer,primary_key=True)
name=Column(String(20),nullable=False)
email=Column(String(20),nullable=False)
picture=Column(String(200))
user_id=Column(Integer,ForeignKey(Food.id))
user=relationship(Food)
engine=create_engine('sqlite:///food.db')
Base.metadata.create_all(engine)