Re: [sqlalchemy] duplicate an object

2015-03-14 Thread moonkid
On 2015-03-13 13:58 Jonathan Vanasco jonat...@findmeon.com wrote: Use a mixin on the classes to create a dict of the column values. Then create a new object with that dict. [..] Looks complex. My solution has only one function, work for nearly all simple declarative_base() derived classes.

Re: [sqlalchemy] duplicate an object

2015-03-14 Thread Jonathan Vanasco
Thats a mixin class that can be added onto any object inheriting from declared_base. You only need one of the `columns_as_dict` options. I showed 3 variations: one that gives all columns, one that lets you specify which columns to include, and another that shows which columns to exclude.

Re: [sqlalchemy] duplicate an object

2015-03-13 Thread moonkid
data-entry instead of an clean empty new-data-dialog. In the latter the user need to type in all data again but e.g. 80% of it is the same then yesterday. Understand? What do you think about this solution: https://stackoverflow.com/questions/29039635/how-to-duplicate-an-sqlalchemy-mapped-object

Re: [sqlalchemy] duplicate an object

2015-03-13 Thread Michael Bayer
care about and which ones you don’t. What do you think about this solution: https://stackoverflow.com/questions/29039635/how-to-duplicate-an-sqlalchemy-mapped-object-the-correct-way if it works for you, then it’s great. It’s not a generalized solution for the whole world, though. It doesn’t

Re: [sqlalchemy] duplicate an object

2015-03-13 Thread Jonathan Vanasco
Use a mixin on the classes to create a dict of the column values. Then create a new object with that dict. You can customize the mixin to include or exclude columns as you wish. I use this approach for revision tracking. Class Duplicable(object) @property def columns_as_dict(self):

Re: [sqlalchemy] duplicate an object

2015-03-12 Thread Michael Bayer
moon...@posteo.org wrote: On 2015-03-08 11:17 Michael Bayer mike...@zzzcomputing.com wrote: there’s no particular “SQLAlchemy way” to do this, What is about make_transient() ? I don't understand this function 100%tly. it changes the state of an object from persistent to

Re: [sqlalchemy] duplicate an object

2015-03-12 Thread Michael Bayer
moon...@posteo.org wrote: On 2015-03-08 11:17 Michael Bayer mike...@zzzcomputing.com wrote: new_obj = MyClass() for attr in mapper.attrs: setattr(new_obj, attr.key, getattr(old_obj, attr.key)) This would copy everything including primary keys and unique members. which is why, “copy

Re: [sqlalchemy] duplicate an object

2015-03-11 Thread moonkid
On 2015-03-08 11:17 Michael Bayer mike...@zzzcomputing.com wrote: there’s no particular “SQLAlchemy way” to do this, What is about make_transient() ? I don't understand this function 100%tly. -- You received this message because you are subscribed to the Google Groups sqlalchemy

Re: [sqlalchemy] duplicate an object

2015-03-11 Thread moonkid
On 2015-03-08 11:17 Michael Bayer mike...@zzzcomputing.com wrote: new_obj = MyClass() for attr in mapper.attrs: setattr(new_obj, attr.key, getattr(old_obj, attr.key)) This would copy everything including primary keys and unique members. I have hard problems with the SQLA-docu. I know that

Re: [sqlalchemy] duplicate an object

2015-03-08 Thread Michael Bayer
moon...@posteo.org wrote: On 2015-03-07 03:17 moon...@posteo.org wrote: Is there a in-build-function to duplicate the instance of a data object (except the primary key)? Isn't there a way for this? Does the sqla-devs reading this list? there’s no particular “SQLAlchemy way” to do

Re: [sqlalchemy] duplicate an object

2015-03-08 Thread moonkid
On 2015-03-07 03:17 moon...@posteo.org wrote: Is there a in-build-function to duplicate the instance of a data object (except the primary key)? Isn't there a way for this? Does the sqla-devs reading this list? -- You received this message because you are subscribed to the Google Groups

[sqlalchemy] duplicate an object

2015-03-06 Thread moonkid
I am using SQLAlchemy with PostgreSQL and Python3. Is there a in-build-function to duplicate the instance of a data object (except the primary key)? Somebody suggested me this self-build function but I would like to use the SQLAlchemy-way if there is one. From