Hi all,

some days ago I had a problem: I needed to copy some objects from the
database preserving their values (and changing only one field). In #django
someone told me that this can be archived easily by setting the primary
key to None and saving. It worked well. But some days later I realized
that ManyToManyFields were not copied, whereas the others did.
This was caused be how ManyToManyFields work, so I had first to save the
objects linked in the ManyToManyField, then to set the private key to
None, save, and add the linked objects again and save them for a second
time.
So, setting the primary key to None is not a very clean solution to copy
fields. What I'd need is an official way to copy objects.
Is there any reason there is no such .copy() method yet? To me it seems
quite reasonable to copy objects as I have to maintain a lots of objects
which differ only in one field and recreating the object from scratch
feels like some kind of strange limitation. Maybe I'm wrong in some way,
but systems have supported copy since a long time...

I would be happy to be able to do something like that:

>>> first = Object.objects.get(name='First')
>>> second = first.copy()
>>>
>>> second.name = 'Second'
>>> # or, that would be also quite clean
>>> second = first.copy(name='Second')
>>>
>>> second.save()

I'd be happy to discuss the pros and cons of such a copy()-function.

The ticket: http://code.djangoproject.com/ticket/4027

regards,
Marek


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to