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):
|
13 | 13 | def __new__(cls, base, name, attrs): |
14 | 14 | new_class = super(SubfieldBase, cls).__new__(cls, base, name, attrs) |
15 | 15 | new_class.contribute_to_class = make_contrib( |
16 | | attrs.get('contribute_to_class')) |
| 16 | attrs.get('contribute_to_class'), new_class) |
17 | 17 | return new_class |
18 | 18 | |
19 | 19 | class Creator(object): |
… |
… |
class Creator(object):
|
31 | 31 | def __set__(self, obj, value): |
32 | 32 | obj.__dict__[self.field.name] = self.field.to_python(value) |
33 | 33 | |
34 | | def make_contrib(func=None): |
| 34 | def make_contrib(func, field_class): |
35 | 35 | """ |
36 | 36 | Returns a suitable contribute_to_class() method for the Field subclass. |
37 | 37 | |
… |
… |
def make_contrib(func=None):
|
44 | 44 | if func: |
45 | 45 | func(self, cls, name) |
46 | 46 | else: |
47 | | super(self.__class__, self).contribute_to_class(cls, name) |
| 47 | super(field_class, self).contribute_to_class(cls, name) |
48 | 48 | setattr(cls, self.name, Creator(self)) |
49 | 49 | |
50 | 50 | return contribute_to_class |