modifiing models of existing apps

hi django forum,

i’m using django for my latest project and im very satisfied, but im missing one feature. openobject, odoos ORM framework makes it possible to extend the models of existing apps, not deriving from it.

this means you can put new fields in models of e.g. an existing crm app without rewriting the controllers and views. they call that delegation inheritance.

in other words. you can make addon1 which extends the customer model of the base crm app and a addon2 which extends the same model with another field and the logic behind it.

now i can have costomer 1 who needs addon1 and customer 2 who needs addon2 and customer 3 who needs both.

if i havent misunderstood something, in django you always make a complete new app and just pull out some models. so you need new controllers and views if you want the same functionality as in the base app or copy and paste the ones from it.

i know - this is only possible by using xml based templating engines and django comes with a html based, but perhaps somebody did a hack for this purpose.

greetings and stay healthy

See the Django docs for model inheritance to see how this is done in Django.

Also, regarding your comparison to ODOO, it’s apples and pumpkins. They’re completely different products addressing separate functional areas. (Django could be something you would use to build something like ODOO - not use it as a replacement for it.)

hi ken,

thanks for your quick answer. of course i have already read the documentation, but there is nothing to read about a feature which is similar to delegation inheritance.

Please define (or provide a reference to something that defines) “delegation inheritance”.

yes youre absolutely right. and for the purpose odoo is made i will further use odoo.

but i have compared open object and django, not odoo and django. openobject is not available without the rest of the application, so im searching for a replacement for openobject.

pure django gives not the whole functions openobject has but is quite flexible, so im asking if anyone has brought this one or two features into django by an addon or so

not much better than my explanation …
Inheritance - Delegation Inheritance in Odoo 13 | Odoo Tutorials.

What features are you looking for? If you’re referring to what ODOO identifies as “delegation inheritance”, I’d need to know what that is before I can offer any suggestions. There’s no glossary that I can find on that defines it outside of an example of how it’s used. (And no, I’m not going to spend 15 minutes trying to watch a video to extract a definition that would take me 15 seconds to read.)

i was wrong. what im searching for is not called delegation inheritance. its the first type of inheritance

you can read it here

Inheritance and extension


If this is the “first type” you’re referencing:

  • creating a new model from an existing one, adding new information to the copy but leaving the original module as-is

(That’s the first bullet from the link you provided)

That’s standard Django model inheritance.

im afraid the anchors are not working on this site. please search for inheritance

Might be easier if you just copy/pasted the applicable text rather than me trying to guess what you’re making references to. (Or at least enough of a snippet to provide some context.)

no in django you only modify the class not the object

sorry the second one

extending models defined in other modules in-place, replacing the previous version

so existing apps show my new fields inside their views

An object is an instance of a class - I don’t follow what you’re trying to say there.

  • extending models defined in other modules in-place, replacing the previous version

Ok, I can see the point here - if you extend a predefined model, your extended class is going to be a new table and not an extension of that existing table.

Something about this is tickling the hair on the back of my neck - I need to do a little more reading about this before I can provide an appropriate response.

its not easy to explain. i will provide some screenshots tomorrow

yes but the point of intrest is what openobject is doing with the new table. i come back with screenshots tomorrow

pythons default behaviour for inheritance ist combining the base class and the child class to one and creating an object out of this aggregate.
inheritance in openobject when

  • extending models defined in other modules in-place, replacing the previous version
    is different. it instanciates the base class … and then it applies the changes introduced by a class which is inherited from the base class. which means its shown in the same view under the same url as the app to which the base class belongs has intended.

thats what i meant as i said modify the class not the object (i know that’s nonsense in object orientated terminology, it’s odoo specific)

in django you always pull models and function from base apps into your own apps by inheritance. you cannot push models, fields and functions into base apps. or am i wrong?

Technically, that is correct. However, since you can override existing templates, views and URLs, it’s a difference that makes no difference.

That’s true as being Python’s standard behavior. However, that’s not required within Django. The two types of inheritance are to do as you describe, or create a OneToOne relationship between your extensions and the base model. (What Django refers to as the “Profile” model.)