diff --git a/changelog b/changelog index a697b887..bb830d8e 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ CHANGELOG * removed default values from all column types * explicit primary key is required (automatic id removed) * added validation on keyname types on .create() +* changed table_name to __table_name__, read_repair_chance to __read_repair_chance__, keyspace to __keyspace__ * changed internal implementation of model value get/set 0.3.3 diff --git a/cqlengine/management.py b/cqlengine/management.py index 90005d2b..b3504b91 100644 --- a/cqlengine/management.py +++ b/cqlengine/management.py @@ -83,7 +83,7 @@ def create_table(model, create_missing_keyspace=True): qs += ['({})'.format(', '.join(qtypes))] - with_qs = ['read_repair_chance = {}'.format(model.read_repair_chance)] + with_qs = ['read_repair_chance = {}'.format(model.__read_repair_chance__)] _order = ["%s %s" % (c.db_field_name, c.clustering_order or 'ASC') for c in model._clustering_keys.values()] if _order: diff --git a/cqlengine/models.py b/cqlengine/models.py index afc2678d..3dca1064 100644 --- a/cqlengine/models.py +++ b/cqlengine/models.py @@ -127,11 +127,12 @@ class BaseModel(object): #table names will be generated automatically from it's model and package name #however, you can also define them manually here - table_name = None + __table_name__ = None #the keyspace for this model - keyspace = None - read_repair_chance = 0.1 + __keyspace__ = None + + __read_repair_chance__ = 0.1 def __init__(self, **values): self._values = {} @@ -165,7 +166,7 @@ class BaseModel(object): @classmethod def _get_keyspace(cls): """ Returns the manual keyspace, if set, otherwise the default keyspace """ - return cls.keyspace or DEFAULT_KEYSPACE + return cls.__keyspace__ or DEFAULT_KEYSPACE def __eq__(self, other): return self.as_dict() == other.as_dict() @@ -180,8 +181,8 @@ class BaseModel(object): otherwise, it creates it from the module and class name """ cf_name = '' - if cls.table_name: - cf_name = cls.table_name.lower() + if cls.__table_name__: + cf_name = cls.__table_name__.lower() else: camelcase = re.compile(r'([a-z])([A-Z])') ccase = lambda s: camelcase.sub(lambda v: '{}_{}'.format(v.group(1), v.group(2).lower()), s) @@ -341,7 +342,7 @@ class ModelMetaClass(type): db_map[col.db_field_name] = field_name #short circuit table_name inheritance - attrs['table_name'] = attrs.get('table_name') + attrs['table_name'] = attrs.get('__table_name__') #add management members to the class attrs['_columns'] = column_dict diff --git a/cqlengine/tests/model/test_class_construction.py b/cqlengine/tests/model/test_class_construction.py index 25cd5906..05e77bde 100644 --- a/cqlengine/tests/model/test_class_construction.py +++ b/cqlengine/tests/model/test_class_construction.py @@ -203,8 +203,8 @@ class TestModelClassFunction(BaseCassEngTestCase): class TestManualTableNaming(BaseCassEngTestCase): class RenamedTest(cqlengine.Model): - keyspace = 'whatever' - table_name = 'manual_name' + __keyspace__ = 'whatever' + __table_name__ = 'manual_name' id = cqlengine.UUID(primary_key=True) data = cqlengine.Text()