@@ -17,11 +17,16 @@ class MenuItem(db.Model):
1717 name = db .Column (db .String ())
1818 price = db .Column (db .Float ())
1919 # image_id = db.Column(db.Integer) # this is probably broken
20- image_id = db .Column (db .Integer , db .ForeignKey (' image.id' ))
21- cart_id = db .Column (db .String , db .ForeignKey (' cart.host' ), nullable = True )
20+ image_id = db .Column (db .Integer , db .ForeignKey (" image.id" ))
21+ cart_id = db .Column (db .String , db .ForeignKey (" cart.host" ), nullable = True )
2222
2323 def __init__ (
24- self , description , name , price , image_id , cart_id = None ,
24+ self ,
25+ description ,
26+ name ,
27+ price ,
28+ image_id ,
29+ cart_id = None ,
2530 ):
2631 self .description = description
2732 self .name = name
@@ -30,7 +35,7 @@ def __init__(
3035 self .cart_id = cart_id
3136
3237 def __repr__ (self ):
33- return ' <id {}>' .format (self .id )
38+ return " <id {}>" .format (self .id )
3439
3540 # something like marshmallow would be a good addition if we were planning to scale this, but
3641 # there's just one model
@@ -41,10 +46,13 @@ def serialize(self):
4146 "imageId" : self .image_id ,
4247 "name" : self .name ,
4348 "price" : self .price ,
44- }
49+ }
50+
4551 @classmethod
4652 def add (cls , menu_item ):
47- item = cls (menu_item .description , menu_item .name , menu_item .price , menu_item .image_id )
53+ item = cls (
54+ menu_item .description , menu_item .name , menu_item .price , menu_item .image_id
55+ )
4856 _commit_item (item )
4957 return item .serialize ()
5058
@@ -59,13 +67,13 @@ def query_by_id(cls, item_id):
5967
6068class Cart (db .Model ):
6169 host = db .Column (db .String , primary_key = True )
62- items = db .relationship (' MenuItem' )
70+ items = db .relationship (" MenuItem" )
6371
6472 def __init__ (self , host ):
6573 self .host = host
6674
6775 def __repr__ (self ):
68- return ' <host {}>' .format (self .host )
76+ return " <host {}>" .format (self .host )
6977
7078 @classmethod
7179 def add_item (cls , host , menu_item ):
@@ -89,16 +97,16 @@ def delete_item_by_id(cls, host, item_id):
8997 break
9098 db .session .commit ()
9199
100+
92101class Image (db .Model ):
93102 id = db .Column (db .Integer , primary_key = True )
94103 data = db .Column (db .LargeBinary )
95104
96-
97105 def __init__ (self , data ):
98106 self .data = data
99107
100108 def __repr__ (self ):
101- return ' <id {}>' .format (self .id )
109+ return " <id {}>" .format (self .id )
102110
103111 @classmethod
104112 def add (cls , raw_data ):
@@ -116,4 +124,3 @@ def delete_image(cls, image_id):
116124 @classmethod
117125 def get_image (cls , image_id ):
118126 return cls .query .filter (Image .id == image_id ).first ()
119-
0 commit comments