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 <glicer...@gmail.com> wrote:
> On Sat, Nov 20, 2010 at 4:37 AM, Joseph (Driftwood Cove Designs) <
>
>
>
> powderfl...@gmail.com> 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 django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to