Ticket #10728: 0002-Allow-subclassing-field-types-that-use-the-SubfieldB.patch

File 0002-Allow-subclassing-field-types-that-use-the-SubfieldB.patch, 1.6 KB (added by Gabriel, 16 years ago)

fix

  • django/db/models/fields/subclassing.py

    From 6fece343020469c7ff7cb188917c1b10c95d38ef Mon Sep 17 00:00:00 2001
    From: Gabriel <g2p.code@gmail.com>
    Date: Sat, 4 Apr 2009 02:22:01 +0200
    Subject: [PATCH 2/2] Allow subclassing field types that use the SubfieldBase metaclass.
    
    ---
     django/db/models/fields/subclassing.py |    6 +++---
     1 files changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/django/db/models/fields/subclassing.py b/django/db/models/fields/subclassing.py
    index 10add10..0f979e7 100644
    a b class SubfieldBase(type):  
    1313    def __new__(cls, base, name, attrs):
    1414        new_class = super(SubfieldBase, cls).__new__(cls, base, name, attrs)
    1515        new_class.contribute_to_class = make_contrib(
    16                 attrs.get('contribute_to_class'))
     16                attrs.get('contribute_to_class'), new_class)
    1717        return new_class
    1818
    1919class Creator(object):
    class Creator(object):  
    3131    def __set__(self, obj, value):
    3232        obj.__dict__[self.field.name] = self.field.to_python(value)
    3333
    34 def make_contrib(func=None):
     34def make_contrib(func, field_class):
    3535    """
    3636    Returns a suitable contribute_to_class() method for the Field subclass.
    3737
    def make_contrib(func=None):  
    4444        if func:
    4545            func(self, cls, name)
    4646        else:
    47             super(self.__class__, self).contribute_to_class(cls, name)
     47            super(field_class, self).contribute_to_class(cls, name)
    4848        setattr(cls, self.name, Creator(self))
    4949
    5050    return contribute_to_class
Back to Top