-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
38 lines (35 loc) · 1.24 KB
/
models.py
File metadata and controls
38 lines (35 loc) · 1.24 KB
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
#!/usr/bin/env python3.6
import os
import uuid
import boto3
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute, BooleanAttribute, MapAttribute, UTCDateTimeAttribute
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection
from functions import get_time_now
class UserIndex(GlobalSecondaryIndex):
"""
This class represents a global secondary index
(for now not used because change in table strcuture)
"""
class Meta:
index_name = 'user-index'
read_capacity_units = 1
write_capacity_units = 1
# All attributes are projected
projection = AllProjection()
user = UnicodeAttribute(default='', hash_key=True)
class Event(Model):
"""
This class define the Event table
"""
class Meta:
table_name = os.environ.get('STAGE', 'dev') + '.events'
region = boto3.Session().region_name
host = 'http://localhost:8000' \
if not os.environ.get('LAMBDA_TASK_ROOT') else None
user = UnicodeAttribute(hash_key=True)
id = UnicodeAttribute(range_key=True)
is_free = BooleanAttribute(default=False)
event_orig = MapAttribute()
event_orig_str = UnicodeAttribute()
created_at = UTCDateTimeAttribute(default=get_time_now)