Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS123-Canteeneo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Willard Torres
CS123-Canteeneo
Commits
29f85a36
Commit
29f85a36
authored
Oct 22, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add models for favorites and reviews
parent
11c5748b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
5 deletions
+66
-5
models.py
canteeneo/models.py
+66
-5
No files found.
canteeneo/models.py
View file @
29f85a36
...
...
@@ -2,14 +2,25 @@ from canteeneo import db
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
import
hashlib
dish_favorites
=
db
.
Table
(
'dish_favorites'
,
db
.
Column
(
'dish_id'
,
db
.
Integer
,
db
.
ForeignKey
(
'dish.id'
)),
db
.
Column
(
'user_id'
,
db
.
Integer
,
db
.
ForeignKey
(
'user.id'
))
)
stall_favorites
=
db
.
Table
(
'stall_favorites'
,
db
.
Column
(
'stall_id'
,
db
.
Integer
,
db
.
ForeignKey
(
'stall.id'
)),
db
.
Column
(
'user_id'
,
db
.
Integer
,
db
.
ForeignKey
(
'user.id'
))
)
class
Stall
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
80
))
description
=
db
.
Column
(
db
.
Text
)
owner_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'owner.id'
))
location_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'location.id'
))
dishes
=
db
.
relationship
(
'Dish'
,
backref
=
'stall'
,
cascade
=
'all,delete'
,
lazy
=
'dynamic'
)
favorites
=
db
.
relationship
(
'Stall'
,
secondary
=
stall_favorites
,
backref
=
db
.
backref
(
'stall'
,
lazy
=
'dynamic'
))
reviews
=
db
.
relationship
(
'StallReview'
,
backref
=
'stall'
,
lazy
=
'dynamic'
)
def
__init__
(
self
,
name
,
description
,
owner_id
,
location_id
):
self
.
name
=
name
...
...
@@ -24,6 +35,8 @@ class Dish(db.Model):
price
=
db
.
Column
(
db
.
Float
)
stall_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'stall.id'
))
image_path
=
db
.
Column
(
db
.
String
(
160
),
unique
=
True
)
favorites
=
db
.
relationship
(
'User'
,
secondary
=
dish_favorites
,
backref
=
db
.
backref
(
'dish'
,
lazy
=
'dynamic'
))
reviews
=
db
.
relationship
(
'DishReview'
,
backref
=
'dish'
,
lazy
=
'dynamic'
)
def
__init__
(
self
,
name
,
description
,
price
,
stall
,
image_path
):
self
.
name
=
name
...
...
@@ -47,9 +60,6 @@ class Owner(db.Model):
self
.
email
=
email
self
.
set_password
(
password
)
def
__repr__
(
self
):
return
self
.
username
def
set_password
(
self
,
password
):
self
.
password
=
generate_password_hash
(
password
)
...
...
@@ -74,3 +84,54 @@ class Location(db.Model):
def
__init__
(
self
,
name
):
self
.
name
=
name
class
User
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
80
))
email
=
db
.
Column
(
db
.
String
(
80
))
password
=
db
.
Column
(
db
.
String
(
160
))
dish_favorites
=
db
.
relationship
(
'Dish'
,
secondary
=
dish_favorites
,
backref
=
db
.
backref
(
'user'
,
lazy
=
'dynamic'
))
stall_favorites
=
db
.
relationship
(
'Stall'
,
secondary
=
stall_favorites
,
backref
=
db
.
backref
(
'user'
,
lazy
=
'dynamic'
))
dish_reviews
=
db
.
relationship
(
'DishReview'
,
backref
=
'user'
,
lazy
=
'dynamic'
)
stall_reviews
=
db
.
relationship
(
'StallReview'
,
backref
=
'user'
,
lazy
=
'dynamic'
)
def
__init__
(
self
,
name
,
email
,
password
):
self
.
name
=
name
self
.
email
=
email
self
.
set_password
(
password
)
def
set_password
(
self
,
password
):
self
.
password
=
generate_password_hash
(
password
)
def
check_password
(
self
,
password
):
return
check_password_hash
(
self
.
password
,
password
)
class
DishReview
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
title
=
db
.
Column
(
db
.
String
(
80
))
body
=
db
.
Column
(
db
.
Text
)
rating
=
db
.
Column
(
db
.
Integer
)
user_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'user.id'
))
dish_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'dish.id'
))
def
__init__
(
self
,
title
,
body
,
rating
,
user_id
,
dish_id
):
self
.
title
=
title
self
.
body
=
body
self
.
rating
=
rating
self
.
user_id
=
user_id
self
.
dish_id
=
dish_id
class
StallReview
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
title
=
db
.
Column
(
db
.
String
(
80
))
body
=
db
.
Column
(
db
.
Text
)
rating
=
db
.
Column
(
db
.
Integer
)
user_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'user.id'
))
stall_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'stall.id'
))
def
__init__
(
self
,
title
,
body
,
rating
,
user_id
,
stall_id
):
self
.
title
=
title
self
.
body
=
body
self
.
rating
=
rating
self
.
user_id
=
user_id
self
.
stall_id
=
stall_id
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment