[Answered ]-Django copy/paste Queryset

1👍

Django 1.4 has bulk_create method that does his job in 1 sql query

👤San4ez

1👍

It doesn’t sound like you want to clone or copy these records – that’s something you should avoid in a normalized database anyway.

If you just want to update a single field, then you can do that with the update queryset method:

MyModel.objects.filter(mailing_list=list_a).update(mailing_list=list_b)

If you’re talking about adding them to a different M2M relationship, then you can do that simply:

mailing_list_b.users.add(*MyModel.objects.filter(mailing_list=list_a))

0👍

In Django 1.3 the solution is to iterate QuerySet and create copies like this:

from copy import deepcopy
old_obj = deepcopy(obj)
old_obj.id = None
old_obj.save()
👤AlexA

Leave a comment