summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-12-04 13:55:45 +0000
committerAndrew Godwin <andrew@aeracode.org>2013-12-04 13:55:45 +0000
commitdf800b160990884246d73786e85b082d9b703b57 (patch)
tree3da450820ece1b80dcf85ca61c218ca06e82ddef
parentab587fa51a3be3ffc6f011189c0abab32dec6155 (diff)
Add clone() method to Field to get clean copies of it.
-rw-r--r--django/db/models/fields/__init__.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 1fa230e1c2..6b2dc2ad21 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -240,6 +240,14 @@ class Field(object):
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):
# Needed for @total_ordering
if isinstance(other, Field):