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

Hi, in my case Im doing a migration from a personal app to Odoo and want to know if I can create models automatically from database tables (as you can do with other ORM's) after the migration.


Thanks in advance!


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

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

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

Hey Jamshid Chungath thanks for the reply, but that's not the question I posted. I know how Odoo works on that way, you make models and the ORM makes tables for you, but Im looking for the reverse action where the ORM makes models from tables, like other ORM's in the market does. Please read the post title carefully!

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

In odoo ORM, you can specify your models, odoo automatically create table based on the model

here is an example

from odoo import models, fields


class Product(models.Model):

_name = 'product.product'

_description = 'Product'


name = fields.Char(string='Product Name', required=True)

description = fields.Text(string='Description')

price = fields.Float(string='Price', digits=(10, 2), required=True)

stock_quantity = fields.Integer(string='Stock Quantity', default=0)


# Many-to-One relationship with Product Category

category_id = fields.Many2one('product.category', string='Category')


class ProductCategory(models.Model):

_name = 'product.category'

_description = 'Product Category'


name = fields.Char(string='Category Name', required=True)

description = fields.Text(string='Description')


# One-to-Many relationship with Product

product_ids = fields.One2many('product.product', 'category_id', string='Products')


Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
лип. 25
1676
database migration Вирішено
1
бер. 23
2322
1
квіт. 17
3592
1
січ. 25
6099
2
лют. 17
10882