Reputation: 45
I need add 2 function save() to one model. How to do?
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Property, self).save(*args, **kwargs)
def save(self, *args, **kwargs):
self.key = ''.join(random.choice(string.letters) for i in xrange(132))
..........
return self
Upvotes: 0
Views: 63
Reputation: 7716
You can't. Even if they have two different signatures it is not possible to have two functions with the same name in Python (and in your case they hardly have a signature).
You can either do:
def save(self, which_save, *args, **kwargs):
if(which_save == 1):
do_something()
elif(which_save == 2):
do_something_else()
else:
raise ValueError
or two different names:
def save_a(self, *args, **kwargs):
# some code
def save_b(self, *args, **kwargs):
# some other code
or you can mix the two - have save
, save_a
and save_b
.
Upvotes: 1