Skip to Content
Menu
This question has been flagged

I will do an abstract class with some childs, ex: "animal -> extended by dog and extended by cat".

the problem becomes when I want to list all the "animals" in the example.


example code:


class Animal(models.AbstractModel):
_name = "test.animal"

name = fields.Char("Name")
vel = fields.Float("Velocity")


class Dog(models.Model):
_name = "test.dog"
_inherit = ["test.animal"]


class Cat(models.Model):
_name = "test.cat"
_inherit = ["test.animal"]

Thank you
Avatar
Discard

I have a superclasse “Animal” whose is abstract and some subclasses “dog, cat, horse...” whose extends animal.

 

The exemple code is:

 

class Animal(models.AbstractModel):
    _name = "test.animal"

    name = fields.Char("Name")
    vel = fields.Float("Velocity")


class Dog(models.Model):
    _name = "test.dog"
    _inherit = ["test.animal"]


class Cat(models.Model):
    _name = "test.cat"
    _inherit = ["test.animal"]

 

I want to do a view that shows all the “animals”, including “cats, dogs,...”

 

 

De: Ermin Trevisan <trevi@twanda.com>
Enviado el: miércoles, 23 de octubre de 2019 17:23
Para: Joan Aldabó <joan.aldabo@midgard.cat>
Asunto: Re: view for generic class

 

Please be more specific. What is your problem?

Sent by Odoo S.A. using Odoo.

Best Answer

Hi,

you can't create one view to show more models.

When you extend an original model, Odoo create another one. Famework can't show records from more models in the some view. 

If you want something like this you can create an unique class Animal and define a field that set if this animal is a cat, a dog or another one. You can create different menu and action to show list filtered for every animal, yet and you can have a view that show all animals wihout filter.

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
102
5
Jul 24
86802
1
Dec 23
1811
1
May 22
1817
0
Jan 20
2129