Created
September 10, 2019 13:05
-
-
Save almeida1492/8c69d49309fb38b2333a3306b62c3296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Restaurant(Base): | |
__tablename__ = 'restaurant' | |
name = Column(String(80), nullable=False) | |
id = Column(Integer, primary_key=True) | |
class MenuItem(Base): | |
__tablename__ = 'menu_item' | |
name = Column(String(80), nullable=False) | |
id = Column(Integer, primary_key=True) | |
course = Column(String(250)) | |
description = Column(String(250)) | |
price = Column(String(8)) | |
restaurant_id = Column(Integer, ForeignKey('restaurant.id')) | |
restaurant = relationship(Restaurant) | |
@property | |
def serialize(self): | |
return { | |
'name': self.name, | |
'description': self.description, | |
'id': self.id, | |
'price': self.price, | |
'course': self.course, | |
} | |
engine = create_engine('sqlite:///restaurantmenu.db') | |
Base.metadata.create_all(engine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment