Django "bulk_save" and "bulk_update"

UPDATE: ADDED. PLEASE PROVIDE AN EXAMPLE AND I ACCEPT THE BEST ANSWER

UPDATE 2: Explicit example is now included

Running this project when I asked about bulk_create in a separate thread. I was wondering if there is essentially a "bulk_save" way - insert if it does not exist or just upgrade if it already exists.

For instance:

class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) height = models.DecimalField(blank=True, null=True) weight = models.DecimalField(blank=True, null=True) 

I have a list of dictionaries with key-value pairs for these fields. I would like to filter by name and then update the height and / or weight, as these of my players are still growing and conditioning. If there is no easy way to "bulk_save", a bulk update will also be useful.

Link: June 8, 2012 - patch get_or_create () in django project

Link to Bulk_update

+6
source share
1 answer

I just changed the update_many function listed below. It seems that I have already significantly improved speed.

http://people.iola.dk/olau/python/bulkops.py

UPDATE - perhaps DSE2 is also an option.

https://bitbucket.org/weholt/dse2

Speed ​​testing will be updated tomorrow.

+3
source

Source: https://habr.com/ru/post/920097/


All Articles