mirror of https://github.com/django/django.git
Add clone() method to Field to get clean copies of it.
This commit is contained in:
parent
ab587fa51a
commit
df800b1609
|
@ -240,6 +240,14 @@ class Field(object):
|
||||||
keywords,
|
keywords,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
"""
|
||||||
|
Uses deconstruct() to clone a new copy of this Field.
|
||||||
|
Will not preserve any class attachments/attribute names.
|
||||||
|
"""
|
||||||
|
name, path, args, kwargs = self.deconstruct()
|
||||||
|
return self.__class__(*args, **kwargs)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
# Needed for @total_ordering
|
# Needed for @total_ordering
|
||||||
if isinstance(other, Field):
|
if isinstance(other, Field):
|
||||||
|
|
Loading…
Reference in New Issue