diff options
Diffstat (limited to 'opendc')
| -rw-r--r-- | opendc/models/model.py | 5 | ||||
| -rw-r--r-- | opendc/models/rack.py | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/opendc/models/model.py b/opendc/models/model.py index 2507a287..18ea61f4 100644 --- a/opendc/models/model.py +++ b/opendc/models/model.py @@ -278,7 +278,7 @@ class Model(object): self.insert_with_id() - def insert_with_id(self): + def insert_with_id(self, is_auto_generated=True): """Insert this Model into the database without removing its id.""" statement = 'INSERT INTO {} ({}) VALUES ({})'.format( @@ -296,7 +296,8 @@ class Model(object): raise exceptions.ForeignKeyError(e.message) if 'id' in self.COLUMNS_PRIMARY_KEY: - setattr(self, 'id', last_row_id) + if is_auto_generated: + setattr(self, 'id', last_row_id) self.read() def read(self): diff --git a/opendc/models/rack.py b/opendc/models/rack.py index b547afa1..da965849 100644 --- a/opendc/models/rack.py +++ b/opendc/models/rack.py @@ -52,7 +52,7 @@ class Rack(Model): obj.insert() self.id = obj.id - self.insert_with_id() + self.insert_with_id(is_auto_generated=False) def delete(self): """Delete a Rack by deleting its associated object.""" |
