views:

43

answers:

1

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.

+2  A: 

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)
Daniel
Doesn't seem to do the trick - python says it's a syntax error
Nick
you must've used the second one... see my edit
Daniel
+1 for `kwargs.pop`.
Daniel Roseman