Implement copy magic methods on Model
- Add Model.__copy__ - Add Model.__deepcopy__
This commit is contained in:
parent
59c79b8c21
commit
9d89de02df
|
@ -25,6 +25,7 @@ from . import exceptions
|
||||||
|
|
||||||
|
|
||||||
class Model(dict):
|
class Model(dict):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# we overload setattr so set this manually
|
# we overload setattr so set this manually
|
||||||
d = dict(*args, **kwargs)
|
d = dict(*args, **kwargs)
|
||||||
|
@ -91,6 +92,12 @@ class Model(dict):
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return copy.deepcopy(dict(self))
|
return copy.deepcopy(dict(self))
|
||||||
|
|
||||||
|
def __copy__(self):
|
||||||
|
return self.copy()
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
return copy.deepcopy(dict(self), memo)
|
||||||
|
|
||||||
def update(self, other):
|
def update(self, other):
|
||||||
mutation = dict(self.items())
|
mutation = dict(self.items())
|
||||||
mutation.update(other)
|
mutation.update(other)
|
||||||
|
|
Loading…
Reference in New Issue