summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/base.py3
-rw-r--r--django/db/models/fields/__init__.py13
2 files changed, 10 insertions, 6 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 6fad7070ba..40af8a0ed9 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -1,3 +1,4 @@
+import copy
import types
import sys
import os
@@ -111,7 +112,7 @@ class ModelBase(type):
if field.name in names:
raise FieldError('Local field %r in class %r clashes with field of similar name from abstract base class %r'
% (field.name, name, base.__name__))
- new_class.add_to_class(field.name, field)
+ new_class.add_to_class(field.name, copy.deepcopy(field))
if abstract:
# Abstract base models can't be instantiated and don't appear in
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 6e426318f5..7778117fb3 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -1,3 +1,4 @@
+import copy
import datetime
import os
import time
@@ -126,11 +127,13 @@ class Field(object):
return cmp(self.creation_counter, other.creation_counter)
def __deepcopy__(self, memodict):
- # Slight hack; deepcopy() is difficult to do on classes with
- # dynamically created methods. Fortunately, we can get away with doing
- # a shallow copy in this particular case.
- import copy
- return copy.copy(self)
+ # We don't have to deepcopy very much here, since most things are not
+ # intended to be altered after initial creation.
+ obj = copy.copy(self)
+ if self.rel:
+ obj.rel = copy.copy(self.rel)
+ memodict[id(self)] = obj
+ return obj
def to_python(self, value):
"""