What is the Django way to copy and paste Queryset except iterating over records and cloning/saving? E.g. a set of records from table A needs to be selected, some field updated and records inserted back to the original table? A sample use case is adding subscribers from mailing list A to mailing list B. Should it be just a loop iterating over QuerySet and cloning/saving record by record, or there is some method for group operation?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
Django 1.4 has bulk_create method that does his job in 1 sql query
In Django 1.3 the solution is to iterate QuerySet and create copies like this:
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:If you're talking about adding them to a different M2M relationship, then you can do that simply: