Skip to content

Instantly share code, notes, and snippets.

@rmyers
Last active December 16, 2015 17:19
Show Gist options
  • Save rmyers/5470076 to your computer and use it in GitHub Desktop.
Save rmyers/5470076 to your computer and use it in GitHub Desktop.
class DatabaseModelBase(models.ModelBase):¬
_auto_generated_atts = ['id']
¬
@classmethod¬
def create(cls, **values):¬
values = cls.get_auto_generated_values(**values)¬
if hasattr(cls, 'deleted') and 'deleted' not in values:¬
values['deleted'] = False¬
values['created'] = utils.utcnow()¬
instance = cls(**values).save()¬
if not instance.is_valid():¬
raise exception.InvalidModelError(errors=instance.errors)¬
return instance¬
¬
@classmethod¬
def get_auto_generated_values(cls, **values):
for v in cls._auto_generated_attrs:
if v not in values:
values[v] = utils.gen_uuid()
return values
class Action(dbmodels.DatabaseModelBase):
"""Defines an Instance Action."""¬
_auto_generated_attrs = []
_data_fields = ['instance_uuid', 'updated_at', 'request_id', 'user_id',¬
'start_time', 'finish_time', 'message']¬
_table_name = 'actions'¬
¬
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment