Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
5823 Widoki

Hello everybody!

I have created 2 classes which are really similar:
class A(models.Model):
    _name = 'product.template'
    _inherit = 'product.template'
    file = fields.Binary(_('File'), required=False)
   
class B(models.Model):
    _name = "product.template"
    _inherit = 'product.template'
....   
...
my_file = self.env['product.template'].file

I want to access the file field of class A from class B but I always get value none/False eventhough i have a file uploaded. I tried with other custom fields also but what I get is nothing.
Is there a way to access fields from the other classes of the inherited product.template?


Thanks a lot in advance!

Awatar
Odrzuć
Najlepsza odpowiedź

Because both of your models are inheriting the same base model, your initial field, file, will already exist and can be accessed through the file field in model B.

If you want to duplicate the file onto another field you may want to try assigning a default: 

my_file = fields.Binary(....... default=self.file)

Awatar
Odrzuć
Najlepsza odpowiedź

I don't think you really need self.env['product.template'] here, it should probably just look like my_file = self.file

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thank you for your answer.

That was the first what i have tried, but i still get the none/False eventhough i have a file uploaded. I tried also to inherit class B from class A, still no effect.
I may have to read it directly from database?!

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
kwi 19
3684
2
lip 24
1684
2
sie 23
4388
0
maj 22
1065
0
gru 21
2254