[IMP] fields: simplify definition of ID field

This commit is contained in:
Raphael Collet 2015-03-11 12:26:02 +01:00
parent ffa7f28d34
commit 915af86a91
1 changed files with 6 additions and 6 deletions

View File

@ -75,8 +75,8 @@ class MetaField(type):
def __init__(cls, name, bases, attrs): def __init__(cls, name, bases, attrs):
super(MetaField, cls).__init__(name, bases, attrs) super(MetaField, cls).__init__(name, bases, attrs)
if cls.type: if cls.type and cls.type not in MetaField.by_type:
cls.by_type[cls.type] = cls MetaField.by_type[cls.type] = cls
# compute class attributes to avoid calling dir() on fields # compute class attributes to avoid calling dir() on fields
cls.column_attrs = [] cls.column_attrs = []
@ -1784,15 +1784,15 @@ class Serialized(Field):
class Id(Field): class Id(Field):
""" Special case for field 'id'. """ """ Special case for field 'id'. """
type = 'integer'
string = 'ID'
store = True store = True
#: Can't write this! #: Can't write this!
readonly = True readonly = True
def __init__(self, string=None, **kwargs):
super(Id, self).__init__(type='integer', string=string, **kwargs)
def to_column(self): def to_column(self):
self.column = fields.integer('ID') self.column = fields.integer(self.string)
return self.column return self.column
def __get__(self, record, owner): def __get__(self, record, owner):