On 1/11/06, Mike <[EMAIL PROTECTED]> wrote: > How do I duplicate objects? Save_as style. > > Something like... > a=choices.get_list()[0] > a.poll_id = 2 > a.save() > > Except not to update the previous record
You could do this: a = choices.get_list()[0] a.poll_id = 2 new_choice = choices.Choice(**a.__dict__()) new_choice.save() This exploits the fact that Python objects have a built-in __dict__() method that returns a dictionary of attribute -> value items. The "**" (double asterisks) tell Python to expand the dictionary value into keyword arguments. For example the following two statements are functionally identical: write_love_letter(to='python', from='adrian') write_love_letter(**{'to': 'python', 'from': 'adrian'}) Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org