3

From this question I got the idea of overriding deepycopy in my Django models. I took the code snippet from that question and put it into my model with the following signature:

def __deepcopy__(self, *args, **kwargs):

However I want to be able to pass 'field' and 'value' parameters as well, but this doesn't work. When I invoke:

deepcopy(s1, field='foo',value='bar')

with the params attempting to be pulled from the method body using kwargs['field'] and kwargs['value'], I get the following error:

File "<stdin>", line 1, in <module>
TypeError: deepcopy() got an unexpected keyword argument 'field'

By the way, I'm assuming I have to import the deepcopy method for it to be used at all, which I'm doing with:

from copy import deepcopy

There is some error in my understanding here, thanks in advance for explaining.

Community
  • 1
  • 1
Neil
  • 7,042
  • 9
  • 43
  • 78

1 Answers1

1

Not sure what exactly you're trying to do with the field and value parameters, but you can't do it in the way you're trying to. Since you're not doing anything to the deepcopy function itself, it doesn't know anything about the changes you made in your models deepcopy method.

If you check out the docs on copying it explains how to override copy and deepcopy http://docs.python.org/library/copy.html

If you really need to be passing in options when copying, you might consider making your own method instead of trying to override built-in behavior.

Hope this helps! Please feel free to respond with more detail about what you're trying to do with your additional arguments.

enzondio
  • 93
  • 5