app/django/db/models/fields/subclassing.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
     3 
     3 
     4 Add SubfieldBase as the __metaclass__ for your Field subclass, implement
     4 Add SubfieldBase as the __metaclass__ for your Field subclass, implement
     5 to_python() and the other necessary methods and everything will work seamlessly.
     5 to_python() and the other necessary methods and everything will work seamlessly.
     6 """
     6 """
     7 
     7 
     8 from django.utils.maxlength import LegacyMaxlength
     8 class SubfieldBase(type):
     9 
       
    10 class SubfieldBase(LegacyMaxlength):
       
    11     """
     9     """
    12     A metaclass for custom Field subclasses. This ensures the model's attribute
    10     A metaclass for custom Field subclasses. This ensures the model's attribute
    13     has the descriptor protocol attached to it.
    11     has the descriptor protocol attached to it.
    14     """
    12     """
    15     def __new__(cls, base, name, attrs):
    13     def __new__(cls, base, name, attrs):
    48         else:
    46         else:
    49             super(self.__class__, self).contribute_to_class(cls, name)
    47             super(self.__class__, self).contribute_to_class(cls, name)
    50         setattr(cls, self.name, Creator(self))
    48         setattr(cls, self.name, Creator(self))
    51 
    49 
    52     return contribute_to_class
    50     return contribute_to_class
    53