-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
63 lines (51 loc) · 2.25 KB
/
models.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
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
"""
This file defines the database models
"""
import datetime
from .common import db, Field, auth
from pydal.validators import *
from pydal.validators import IS_URL
def get_user_email():
return auth.current_user.get('email') if auth.current_user else None
def get_time():
return datetime.datetime.utcnow()
# Define your table below
#
# db.define_table('thing', Field('name'))
#
# always commit your models to avoid problems later
db.define_table('pantry',
Field('user_id', 'reference auth_user'),
Field('item', requires=IS_NOT_EMPTY()),
# Field('quantity', 'float', requires=IS_FLOAT_IN_RANGE(0, 1e6)),
)
# Here is an ideal recipes database schema? May be hard to parse an AI response into these fields
# The recipes table holds all recipes generated by AI or manually by users
# db.define_table('recipes',
# Field('created_by', 'reference auth_user'),
# Field('title', 'string', requires=IS_NOT_EMPTY()),
# Field('description', 'text'),
# Field('ingredients', 'list:string'),
# Field('instructions', 'text'),
# Field('created_at', 'datetime', default=get_time()),
# )
# Here is a simplified recipes table that can easily hold an AI response as a string
db.define_table('recipes',
Field('created_by', 'reference auth_user'),
Field('title', 'text'),
Field('ingredients', 'list:string'),
Field('instructions', 'list:string'),
Field('created_at', 'datetime', default=get_time()),
)
# The stared_recipe table holds relationships between users and a recipe they have starred
# Querry all the stared recipes for a user by asking for all records where user=user
db.define_table('favorites',
Field('user_id', 'reference auth_user'),
Field('title', 'text'),
Field('ingredients', 'list:string'),
Field('instructions', 'list:string'),
Field('pinned', 'boolean', default=False),
Field('favorited_at', 'datetime', default=get_time()),
Field('imageUrl', 'string', requires=IS_URL()),
)
db.commit()