0

This should be easy and there is another question on SO that addresses the issue ( passing an argument to a custom save() method ) but that solution isn't working for me. In my view I have form.save('test string') and in the corresponding model I have

def save(self, test, *args, **kwargs):
    x = test
    ...
    super(MyModel, self).save(*args, **kwargs)

But I keep getting save() missing 1 required positional argument: 'test' I have tried form.save(test='test string') but that results in save() got an unexpected keyword argument 'test'. Finally, I changed the method signature to def save(self, *args, **kwargs) and then in the view tried form.save({'test': 'test string'}) there is no error but nothing appears in the kwargs.

I'm using django 1.10 if that matters. Please help and thank you!

Community
  • 1
  • 1
r_zelazny
  • 517
  • 3
  • 19
  • http://stackoverflow.com/questions/1769403/understanding-kwargs-in-python Your problem is about the comprehension of *args and **kwargs – Wilfried Feb 24 '17 at 15:23
  • You seem to be confused between the form and the model; you're modifying the model save method, but you're calling the form save. You may need to explain in more detail what you're actually trying to do. – Daniel Roseman Feb 24 '17 at 15:24
  • I was wondering about that but when I call form.save() I do reach the save() method on the model (assuming I don't worry about passing arguments). I'm trying to populate some fields in the modelform based upon fields from another form in the same template that gets submitted along with the modelform. – r_zelazny Feb 24 '17 at 15:37
  • hack, assign in self. like `self.x=test` then you can get `x` in `save` method. – vinay kumar Feb 24 '17 at 17:34

0 Answers0