def pg_bulk_update(model, filter_name, update_name,
                   filter_column_data, update_column_data, cursor=None):
    cursor = cursor or con.cursor()
    # Get table name and column name for filter and update attributes as
    # stored in database.
    db_table = model._meta.db_table
    model_filter = model._meta.get_field(filter_name).column
    model_update = model._meta.get_field(update_name).column
    # Input data as Django sanitized parameters,
    cursor.execute(
        "UPDATE " + db_table +
        " SET " + model_update + " = input.update" +
        " FROM (SELECT unnest(%s), unnest(%s)) AS input (filter, update)"
        " WHERE " + model_filter + " = input.filter;", [filter_column_data,
                                                        update_column_data])
Postgres database utility to quickly update an entire column in a table
dataset/ETHPy150Open jfalkner/Efficient-Django-QuerySet-Use/demo/django_db_utils/__init__.py/pg_bulk_update