Created
April 26, 2013 19:46
-
-
Save hub-cap/5469849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DatabaseModelBase(models.ModelBase):¬ | |
¬ | |
@classmethod¬ | |
def create(cls, **values):¬ | |
if 'id' not in values:¬ | |
values['id'] = cls.uuid_strategy(**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 uuid_strategy(cls, **values):¬ | |
return uuidutils.generate_uuid()¬ | |
¬ | |
................ | |
class Action(dbmodels.DatabaseModelBase):¬ | |
"""Defines an Instance Action."""¬ | |
¬ | |
_data_fields = ['instance_uuid', 'updated_at', 'request_id', 'user_id',¬ | |
'start_time', 'finish_time', 'message']¬ | |
_table_name = 'actions'¬ | |
¬ | |
@classmethod¬ | |
def uuid_strategy(cls, **values):¬ | |
return None¬ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment