Re: [0.91] Model, subclassing, accessing superclass ?
Laurent RAHUEL wrote: > Ooops, > > It should be : > > class Derived(Parent): > > def _pre_save(self): > do_some_other_things_here > self.my_method() > > Indentation problem ;-) Thanks Laurent, but there was a typo in my original post !-) It should have been: class Parent(meta.Model): ... def my_method(self): do_some_thing_here class Derived(Parent): def my_method(self): do_some_other_things_here try: Parent.my_method() except NameError: try: parents.Parent.my_method() except NameError: print "this (hum) 'magic' mumbo-jumbo is a royal PITA and " " sucks big time" print "(too bad 0.92 is not released yet)" -- bruno desthuilliers développeur [EMAIL PROTECTED] http://www.modulix.com --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: [0.91] Model, subclassing, accessing superclass ?
Ooops, It should be : class Derived(Parent): def _pre_save(self): do_some_other_things_here self.my_method() Indentation problem ;-) Laurent Le Jeudi 9 Mars 2006 14:21, Laurent RAHUEL a écrit : > Le Jeudi 9 Mars 2006 12:58, bruno desthuilliers a écrit : > > Hi, > > > hello hello > > > > I must be a bit dumb, but I find myself a bit stucked with model > > subclassing. Here's the problem: how does one call on the superclass > > method when extending this method in the subclass ? ie: > > > > class Parent(meta.Model): > > > > def my_method(self): > > do_something_here > > > > > > class Derived(Parent): > > > > def _pre_save(self): > > do_some_other_things_here > > Parent.my_method(self) # raises NameError, "Parent" is not defined > > parents.Parent.my_method(self) # idem, "parents" is not defined > > I guess you should do > > class Derived(Parent): > > def _pre_save(self): > do_some_other_things_here > self.my_method() > > You just inherit fields and methods from Parent. Your object is not a child > of Parent but an "extension" of Parent. > > Regards, > > Laurent. > > > Is this a known issue, or I'm I missing something ? FWIW, the method I'm > > trying to extend is actually _pre_save() - but I don't think it has much > > to do with this problem.. > > > > NB : I've solved the problem at hand using a template method pattern as > > a workaround, but if the bug is - as often - between the chair and the > > keyboard, please let me know... > > > > TIA > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
[0.91] Model, subclassing, accessing superclass ?
hello hello I must be a bit dumb, but I find myself a bit stucked with model subclassing. Here's the problem: how does one call on the superclass method when extending this method in the subclass ? ie: class Parent(meta.Model): def my_method(self): do_something_here class Derived(Parent): def _pre_save(self): do_some_other_things_here Parent.my_method(self) # raises NameError, "Parent" is not defined parents.Parent.my_method(self) # idem, "parents" is not defined Is this a known issue, or I'm I missing something ? FWIW, the method I'm trying to extend is actually _pre_save() - but I don't think it has much to do with this problem.. NB : I've solved the problem at hand using a template method pattern as a workaround, but if the bug is - as often - between the chair and the keyboard, please let me know... TIA -- bruno desthuilliers développeur [EMAIL PROTECTED] http://www.modulix.com --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---