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!

4
  • stackoverflow.com/questions/1769403/… Your problem is about the comprehension of *args and **kwargs Commented Feb 24, 2017 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. Commented Feb 24, 2017 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. Commented Feb 24, 2017 at 15:37
  • hack, assign in self. like self.x=test then you can get x in save method. Commented Feb 24, 2017 at 17:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.