diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
index 69dd527..63007d7 100644
a
|
b
|
|
1 | 1 | """ |
2 | 2 | Classes allowing "generic" relations through ContentType and object-id fields. |
3 | 3 | """ |
4 | | |
| 4 | import copy |
5 | 5 | from functools import partial |
6 | 6 | from django.core.exceptions import ObjectDoesNotExist |
7 | 7 | from django.db import connection |
… |
… |
class GenericForeignKey(object):
|
25 | 25 | self.ct_field = ct_field |
26 | 26 | self.fk_field = fk_field |
27 | 27 | |
| 28 | def clone(self): |
| 29 | return copy.copy(self) |
| 30 | |
28 | 31 | def contribute_to_class(self, cls, name): |
29 | 32 | self.name = name |
30 | 33 | self.model = cls |
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 4b3220b..bd8f2c5 100644
a
|
b
|
class ModelBase(type):
|
165 | 165 | else: |
166 | 166 | # .. and abstract ones. |
167 | 167 | for field in parent_fields: |
168 | | new_class.add_to_class(field.name, copy.deepcopy(field)) |
| 168 | new_class.add_to_class(field.name, field.clone()) |
169 | 169 | |
170 | 170 | # Pass any non-abstract parent classes onto child. |
171 | 171 | new_class._meta.parents.update(base._meta.parents) |
… |
… |
class ModelBase(type):
|
186 | 186 | 'with field of similar name from '\ |
187 | 187 | 'abstract base class %r' % \ |
188 | 188 | (field.name, name, base.__name__)) |
189 | | new_class.add_to_class(field.name, copy.deepcopy(field)) |
| 189 | new_class.add_to_class(field.name, field.clone()) |
190 | 190 | |
191 | 191 | if abstract: |
192 | 192 | # 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 47735a8..dd51cc5 100644
a
|
b
|
class Field(object):
|
123 | 123 | return cmp(self.creation_counter, other.creation_counter) |
124 | 124 | |
125 | 125 | def __deepcopy__(self, memodict): |
126 | | # We don't have to deepcopy very much here, since most things are not |
| 126 | # Outside of model initialization, a field instance is immutable by |
| 127 | # convention. In model initialiazation you should not use deepcopy to |
| 128 | # get a new instance similar to another one. Use clone instead. |
| 129 | return self |
| 130 | |
| 131 | def clone(self): |
| 132 | # We don't have to clone very much here, since most things are not |
127 | 133 | # intended to be altered after initial creation. |
128 | 134 | obj = copy.copy(self) |
129 | 135 | if self.rel: |
130 | 136 | obj.rel = copy.copy(self.rel) |
131 | | memodict[id(self)] = obj |
132 | 137 | return obj |
133 | 138 | |
134 | 139 | def to_python(self, value): |
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 0cd52a3..a108795 100644
a
|
b
|
class Options(object):
|
54 | 54 | # from *other* models. Needed for some admin checks. Internal use only. |
55 | 55 | self.related_fkey_lookups = [] |
56 | 56 | |
| 57 | def __deepcopy__(self, memo): |
| 58 | return self |
| 59 | |
57 | 60 | def contribute_to_class(self, cls, name): |
58 | 61 | from django.db import connection |
59 | 62 | from django.db.backends.util import truncate_name |