From df800b160990884246d73786e85b082d9b703b57 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 4 Dec 2013 13:55:45 +0000 Subject: [PATCH] Add clone() method to Field to get clean copies of it. --- django/db/models/fields/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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):