Multiple inheritance model
I'm trying to integrate two existing apps, both of which provide a
django Model - call them ModelA and ModelB - my app's model needs to
inherit from both of these.
I know django models support multiple inheritance, but both ModelA and
ModelB define a Meta class, override the save() method, etc., so that
won't work.
What will work very nicely is for ModelB to simply inherit from
ModelA, but since both are 3rd party apps, I don't want to hack their
code.
So, I need a clever idea for how I can take this inheritance
hierarchy:
django.Model
/ \
ModelA ModelB
\ /
MyModel
and **logically** convert it, without touching code in ModelA or
ModelB, to this:
django.Model
|
ModelA
|
ModelB
|
MyModel
One idea I had was this:
class MyModel(ModelA, ModelB):
...
Meta:
# copy of ModelB's Meta code
def foo(self, *args, **kwargs):
ModelA.foo(self, *args, **kwargs)
ModelB.foo(self, *args, **kwargs)
But this approach fails on the save() - both Models do some processing
before and after the call to super.save().
The annoying thing about this problem is that it's very easy to hack a
solution by modifying the code for ModelB - just one tiny little
change - but this isn't really an option since I want the app I'm
building to be re-usable, and don't want to distribute it with a
hacked copy of another app.
hoping someone out there more clever than I can offer an idea?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home