| 6 | |
| 7 | |
| 8 | class TodoModel(Model): |
| 9 | class Meta: |
| 10 | table_name = os.environ['DYNAMODB_TABLE'] |
| 11 | if 'ENV' in os.environ: |
| 12 | host = 'http://localhost:8000' |
| 13 | else: |
| 14 | region = 'eu-central-1' |
| 15 | host = 'https://dynamodb.eu-central-1.amazonaws.com' |
| 16 | |
| 17 | todo_id = UnicodeAttribute(hash_key=True, null=False) |
| 18 | text = UnicodeAttribute(null=False) |
| 19 | checked = BooleanAttribute(null=False) |
| 20 | createdAt = UTCDateTimeAttribute(null=False, default=datetime.now()) |
| 21 | updatedAt = UTCDateTimeAttribute(null=False) |
| 22 | |
| 23 | def save(self, conditional_operator=None, **expected_values): |
| 24 | self.updatedAt = datetime.now() |
| 25 | super(TodoModel, self).save() |
| 26 | |
| 27 | def __iter__(self): |
| 28 | for name, attr in self._get_attributes().items(): |
| 29 | yield name, attr.serialize(getattr(self, name)) |