On Friday, January 28, 2011 9:21:48 AM UTC, Jaroslav Dobrek wrote:
>
> Hi, 
>
> if I have got several models that have identical code, except for 
> their save method, how can I use an abstract base class for them? Will 
> I have to overwrite save() for each model? Or is there a generic way 
> to define save(), i.e. a way that I have to use only once -- in the 
> abstract base class? 
>
> class BMW(models.Model): 
>    ... 
>   save def save(self, *args, **kwargs): 
>         do_something() 
>         super(BMW, self).save(*args, **kwargs) 
>
> class Fiat(models.Model): 
>    ... 
>   save def save(self, *args, **kwargs): 
>         do_something() 
>         super(Fiat, self).save(*args, **kwargs) 
>
> Jaroslav


The whole point of subclassing is that subclasses inherit models from the 
superclass. That's how the model save() method is definted in the first 
place, if you don't override it. What exactly are you having problems with?
--
DR. 

-- 
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.

Reply via email to