Alex Rivera | Logout

passing an argument to a custom save() method

Asked 2010-03-29T02:09:29.540
11

How do I pass an argument to my custom save method, preserving proper *args, **kwargs for passing to te super method? I was trying something like:

form.save(my_value)

and

def save(self, my_value=None, *args, **kwargs):

   super(MyModel, self).save(*args, **kwargs)

   print my_value

But this doesn't seem to work. What am I doing wrong?

Edit: I found this example (see the last message, for passing 'reorder'): http://groups.google.com/group/django-users/browse_thread/thread/b285698ea3cabfc9/6ce8a4517875cb40?lnk=raot

This is essentially what I am trying to do, but my_value is said to be an unexpected argument for some reason.

Edit
Report

1 Answer

26

Keyword arguments must follow the positional arguments. Try this instead:

def save(self, my_value, *args, **kwargs):
    ....

or:

def save(self, *args, **kwargs):
    my_value = kwargs.pop('my_value', None)
answered 2010-03-29T02:26:18.313

Your Answer