Below is the basic layout - I posted a simplified version of the two
model classes here: http://pastebin.com/Xc3KLrQx
ModelA.save():
if (some condition):
super().save_base()
else:
super().save()
ModelB.save():
is_new_model = pk == None
super().save()
if (is_new_model):
do some stuff
else: # update
do some other stuff
On Nov 20, 5:06 am, Marc Aymerich <[email protected]> wrote:
> On Sat, Nov 20, 2010 at 4:37 AM, Joseph (Driftwood Cove Designs) <
>
>
>
> [email protected]> wrote:
> > 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().
>
> Hi,
> How ModelA and ModelB save method looks like?
>
> --
> Marc
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.