RE: abstract base class and overwriting save()

2011-01-28 Thread Chris Matthews
The "save def save(self, *args, **kwargs):" should not have the leading save.

Also, if you are making a car system then this structure seems more appropriate:
class CarMake(models.Model):
   ...


class Car(models.Model):
   make = models.ForeignKey(CarMaker)
   ...
 def save(self, *args, **kwargs):
do_something()
super(Car, self).save(*args, **kwargs)



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Daniel Roseman
Sent: 28 January 2011 11:36
To: django-users@googlegroups.com
Subject: Re: abstract base class and overwriting save()

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.

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



Re: abstract base class and overwriting save()

2011-01-28 Thread Jaroslav Dobrek
> 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?

It seems that my problems were due to another mistake of mine. I was
thinking in a too complicated way. You are right: nothing has to be
done, just inherit. Thank you.

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



Re: abstract base class and overwriting save()

2011-01-28 Thread Daniel Roseman
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.