On Fri, 2009-01-30 at 12:19 -0800, Daniel Roseman wrote: [...] > This is an ideal case for mixins. A mixin is a basic class which is > 'mixed in' to other classes, which inherit both the attributes of > their base class and the mixin class. So, for example, you could do: > > class MyMixin(object): > def as_span(self): > .... > > class MyForm(forms.Form, MyMixin): > ... > > class MyModelForm(forms.ModelForm, MyMixin): > ...
You have to put the mixin class before the class you're trying to overrides. Python's method resolution order is essentially "first to last" for immediate parent classes. The way you've written the above, any name "foo" will first be looked up in forms.ModelForm and, only if it does exist there, will it be lookup up in MyMixin -- which is backwards from what is intended. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---