Django

Code

Changeset 7431

Show
Ignore:
Timestamp:
04/16/08 03:09:18 (5 months ago)
Author:
mtredinnick
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/base.py

    r7345 r7431  
     1import copy 
    12import types 
    23import sys 
     
    112113                        raise FieldError('Local field %r in class %r clashes with field of similar name from abstract base class %r' 
    113114                                % (field.name, name, base.__name__)) 
    114                     new_class.add_to_class(field.name, field
     115                    new_class.add_to_class(field.name, copy.deepcopy(field)
    115116 
    116117        if abstract: 
  • django/branches/queryset-refactor/django/db/models/fields/__init__.py

    r7341 r7431  
     1import copy 
    12import datetime 
    23import os 
     
    127128 
    128129    def __deepcopy__(self, memodict): 
    129         # Slight hack; deepcopy() is difficult to do on classes with 
    130         # dynamically created methods. Fortunately, we can get away with doing 
    131         # a shallow copy in this particular case. 
    132         import copy 
    133         return copy.copy(self) 
     130        # We don't have to deepcopy very much here, since most things are not 
     131        # intended to be altered after initial creation. 
     132        obj = copy.copy(self) 
     133        if self.rel: 
     134            obj.rel = copy.copy(self.rel) 
     135        memodict[id(self)] = obj 
     136        return obj 
    134137 
    135138    def to_python(self, value):