Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2819 Представления

Given these classes:

class years(models.Model): 
_name = 'years'
name = fields.Integer(required=True)

For different years I have different categories.

class category(models.Model): 
_name = 'category'
year_id = fields.Many2one('years', required=True, default=get_year)
name = fields.Char(required=True)
class parent(models.Model):
_name = 'parent'
  name = fields.Char(required=True)
year_id = fields.Many2one('years', required=True, default=get_year)
class child(models.Model): 
_name = 'child'
parent_id = fields.Many2one('parent', required=True)
name = fields.Char(required=True)
year_id = fields.Many2one('years', required=True, default=get_year)
category_id = fields.Many2one('category', required=True)
value = fields.Float(required=True)

The data looks like this:

years

id name
1 2015
2 2016

category

id year_id name
1 1 Sample 1
2 1 Sample 2
3 2 Sample 3
4 2 Sample 4

parent:

id name       year_id
1 Parent 1 1

child should be this:

id parent_id name    year_id category_id value
1 1 Child 1 1 1 154.452
1 1 Child 2 1 2 100

instead of that I have this:

id parent_id name      year_id category_id value
1  1         Child 1 1 1 154.452
1 1 Child 2 1 4 100

My question is: How can I "inherit" the year_id in the child record from the parent, and how can I limit the categories in the dropdown list (Many2one) to that specific year?

As I've seen I cannot have a related field parent_id.year_id as during the creation this value is not set so I cannot use a domain restriction of the category to that specific year.


Any idea?


Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
апр. 24
8895
0
мар. 16
3053
3
июл. 25
8625
1
мая 25
917
0
янв. 24
1655