Ticket #16759: 16759.diff

File 16759.diff, 3.3 KB (added by Anssi Kääriäinen, 13 years ago)
  • django/contrib/contenttypes/generic.py

    diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
    index 69dd527..63007d7 100644
    a b  
    11"""
    22Classes allowing "generic" relations through ContentType and object-id fields.
    33"""
    4 
     4import copy
    55from functools import partial
    66from django.core.exceptions import ObjectDoesNotExist
    77from django.db import connection
    class GenericForeignKey(object):  
    2525        self.ct_field = ct_field
    2626        self.fk_field = fk_field
    2727
     28    def clone(self):
     29        return copy.copy(self)
     30
    2831    def contribute_to_class(self, cls, name):
    2932        self.name = name
    3033        self.model = cls
  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 4b3220b..bd8f2c5 100644
    a b class ModelBase(type):  
    165165            else:
    166166                # .. and abstract ones.
    167167                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())
    169169
    170170                # Pass any non-abstract parent classes onto child.
    171171                new_class._meta.parents.update(base._meta.parents)
    class ModelBase(type):  
    186186                                     'with field of similar name from '\
    187187                                     'abstract base class %r' % \
    188188                                        (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())
    190190
    191191        if abstract:
    192192            # Abstract base models can't be instantiated and don't appear in
  • django/db/models/fields/__init__.py

    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):  
    123123        return cmp(self.creation_counter, other.creation_counter)
    124124
    125125    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
    127133        # intended to be altered after initial creation.
    128134        obj = copy.copy(self)
    129135        if self.rel:
    130136            obj.rel = copy.copy(self.rel)
    131         memodict[id(self)] = obj
    132137        return obj
    133138
    134139    def to_python(self, value):
  • django/db/models/options.py

    diff --git a/django/db/models/options.py b/django/db/models/options.py
    index 0cd52a3..a108795 100644
    a b class Options(object):  
    5454        # from *other* models. Needed for some admin checks. Internal use only.
    5555        self.related_fkey_lookups = []
    5656
     57    def __deepcopy__(self, memo):
     58        return self
     59
    5760    def contribute_to_class(self, cls, name):
    5861        from django.db import connection
    5962        from django.db.backends.util import truncate_name
Back to Top