adding method for determining which column values have changed
This commit is contained in:
@@ -409,6 +409,10 @@ class BaseModel(object):
|
||||
""" Deletes this instance """
|
||||
self.__dmlquery__(self.__class__, self, batch=self._batch).delete()
|
||||
|
||||
def get_changed_columns(self):
|
||||
""" returns a list of the columns that have been updated since instantiation or save """
|
||||
return [k for k,v in self._values.items() if v.changed]
|
||||
|
||||
@classmethod
|
||||
def _class_batch(cls, batch):
|
||||
return cls.objects.batch(batch)
|
||||
|
||||
@@ -42,8 +42,6 @@ class TestModelIO(BaseCassEngTestCase):
|
||||
for cname in tm._columns.keys():
|
||||
self.assertEquals(getattr(tm, cname), getattr(tm2, cname))
|
||||
|
||||
|
||||
|
||||
def test_model_updating_works_properly(self):
|
||||
"""
|
||||
Tests that subsequent saves after initial model creation work
|
||||
@@ -78,7 +76,6 @@ class TestModelIO(BaseCassEngTestCase):
|
||||
assert tm2.text is None
|
||||
assert tm2._values['text'].previous_value is None
|
||||
|
||||
|
||||
def test_a_sensical_error_is_raised_if_you_try_to_create_a_table_twice(self):
|
||||
"""
|
||||
"""
|
||||
@@ -92,6 +89,7 @@ class TestMultiKeyModel(Model):
|
||||
count = columns.Integer(required=False)
|
||||
text = columns.Text(required=False)
|
||||
|
||||
|
||||
class TestDeleting(BaseCassEngTestCase):
|
||||
|
||||
@classmethod
|
||||
@@ -158,6 +156,14 @@ class TestUpdating(BaseCassEngTestCase):
|
||||
assert check.count is None
|
||||
assert check.text is None
|
||||
|
||||
def test_get_changed_columns(self):
|
||||
assert self.instance.get_changed_columns() == []
|
||||
self.instance.count = 1
|
||||
changes = self.instance.get_changed_columns()
|
||||
assert len(changes) == 1
|
||||
assert changes == ['count']
|
||||
self.instance.save()
|
||||
assert self.instance.get_changed_columns() == []
|
||||
|
||||
|
||||
class TestCanUpdate(BaseCassEngTestCase):
|
||||
|
||||
@@ -137,6 +137,7 @@ Model Methods
|
||||
.. method:: delete()
|
||||
|
||||
Deletes the object from the database.
|
||||
|
||||
-- method:: update(**values)
|
||||
|
||||
|
||||
@@ -145,6 +146,10 @@ Model Methods
|
||||
fields. If no fields on the model have been modified since loading, no query will be
|
||||
performed. Model validation is performed normally.
|
||||
|
||||
-- method:: get_changed_columns()
|
||||
|
||||
Returns a list of column names that have changed since the model was instantiated or saved
|
||||
|
||||
Model Attributes
|
||||
================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user