Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
5409 Переглядів

Is there any alternative way to create/write data at once  ?

Now i'm using
for rec in bla :
    vals = {}
    vals['name'] = rec.name

    obj.create(vals)

When i'm trying to create 1000++ data i will be very slow, take 1-3 Hours.
I need alternative way ! Thank You !!




        

Аватар
Відмінити
Найкраща відповідь

Hi @Chaanto

There are several ways that you could use to get that task done. Here I give you 2. Hope it will help you

1- Using Model load method that accept 2 arguments, fields and data. were fields is a list of fields that match the elements in the data rows meaning that the argument with the data need to be a list of rows and every row will be the list of values of the fields in the same order

Model = self.env['model.name']
result = Model.load(
['name', 'value'],
[
['A', '1'],
['B', '2'],
['C', '3']
],
)
2- Using Cursor copy_from by building a CSV with the data to be load using an SQL Copy Commands
fields = ['name', 'value']
self.env.cr.copy_from(io.StringIO(
u'\n'.join(
u"%s\t%s\t%s\t%d" % (
rec.name,
rec
.value
)
for rec in bla
)),
table='model_table',
columns=fields,
)
Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
трав. 18
4124
0
лют. 18
3351
Libary managment Вирішено
2
трав. 23
2101
2
груд. 18
9647
0
трав. 16
3628