How to create Indexes on Custom module?

If you want to create complex indexes, PostgreSQL is capable to combine index from many columns, you need to inherit _auto_init method of the model and execute a CREATE INDEX (using cr.execute) statement after you call the super.

Example:

def _auto_init(self):
    res=super(picking, self)._auto_init()
    self.env.cr.execute("CREATE INDEX custom_idx ON TABLE tablename (field1,field2,...)")
    return res

If you just want to create per column index, just add select=1 in the column definition, like so:

'name' ; fields.char('Name', size=64, select=1)

If you are interested on how a table and it's related objects, read the _auto_init method of BaseModel.

----


DO NOT CLICK THIS https://bit.ly/3biXWMc

Videos fill be uploaded regularly, so subscribe our youtube Channel.

Visit YouTube Channel http://youtube.com/odooindonesia

Untuk trik Odoo lainnya bisa cek Udemy courses http://udemy.com/user/akhmaddaniel

Visit official site http://vitraining.com

One Touch and Go Live with Odoo http://1toucherp.com

Twitter http://Twitter.com/akhdaniel 

Check our blog: http://indonesia.odoo.com


How to create Indexes on Custom module?
vitraining, odoo indonesia
3 July, 2020
Share this post
Archive
Sign in to leave a comment
How to Remove "Create and Edit…" from many2one field.?