Re: What is the correct way to copy an object from one model to a similar model?

2010-09-29 Thread Yo-Yo Ma
Thanks guys. I appreciate the help. On Sep 29, 6:43 am, bruno desthuilliers wrote: > On 29 sep, 12:31, Steve Holden wrote: > > > On 9/29/2010 5:25 AM, Daniel Roseman wrote: > > > You can use the get_all_field_names method in model._meta to get all > > > the actual fields, and set them on the dup

Re: What is the correct way to copy an object from one model to a similar model?

2010-09-29 Thread bruno desthuilliers
On 29 sep, 12:31, Steve Holden wrote: > On 9/29/2010 5:25 AM, Daniel Roseman wrote: > > You can use the get_all_field_names method in model._meta to get all > > the actual fields, and set them on the duplicate: > > >     for field in foo._meta.get_all_field_names(): > >         setattr(spam, get

Re: What is the correct way to copy an object from one model to a similar model?

2010-09-29 Thread Steve Holden
On 9/29/2010 5:25 AM, Daniel Roseman wrote: > On Sep 29, 6:06 am, Yo-Yo Ma wrote: >> I have two models that are identical in structure except one has 2 >> extra fields. The second one is used for record keeping and is never >> edited by users. The system takes the first model and copies it to the

Re: What is the correct way to copy an object from one model to a similar model?

2010-09-29 Thread Daniel Roseman
On Sep 29, 6:06 am, Yo-Yo Ma wrote: > I have two models that are identical in structure except one has 2 > extra fields. The second one is used for record keeping and is never > edited by users. The system takes the first model and copies it to the > second model, adding some extra meta informatio

Re: What is the correct way to copy an object from one model to a similar model?

2010-09-29 Thread Antoni Aloy
You can use also introspection if the number of attributes is high. http://stackoverflow.com/questions/3818825/python-what-is-the-correct-way-to-copy-an-objects-attributes-over-to-another 2010/9/29 Yo-Yo Ma : > I have two models that are identical in structure except one has 2 > extra fields. The

What is the correct way to copy an object from one model to a similar model?

2010-09-28 Thread Yo-Yo Ma
I have two models that are identical in structure except one has 2 extra fields. The second one is used for record keeping and is never edited by users. The system takes the first model and copies it to the second model, adding some extra meta information, all when a certain action is performed aga