1
0
mirror of https://github.com/django/django.git synced 2025-07-05 18:29:11 +00:00

queryset-refactor: Fixed a few inadvertent sharing problems for related fields

in abstract base classes. This means, for example, that many-to-many fields can
be used in abstract base classes.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7431 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-04-16 08:09:18 +00:00
parent a14135e14f
commit b114fecfe4
2 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -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):
"""