Friday, January 28, 2011

abstract base class and overwriting save()

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

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment