I'd been trying to define my own custom column class - based on the source and some wiki notes - but can't get it to work. The aim is to store a list of strings, being able to write and read them as a list (while internally storing them as a single eoln-delimited string.) However, my solution (written below) throws when I try to create a table using the column, saying "cannot be used for automatic schema creation (too abstract)". This is because the customSQLType is not set. So any advice or pointers? Have I misunderstood the necessary inheritance patterns?
class StringListValidator (validators.Validator):
def from_python (self, value, state):
Translates a Python value into one for the database.
This accepts a single string or sequence of strings and stores them as
a single string, delimited by unix-eolns. We assume that there are no
eolns in the strings, and so no escaping is done. Zero length sequences
and None are treated as null strings.
if (type (value) is type ('')):
elif (hasattr (value, '__len__')):
return '\n'.join (value)
elif (value is None):
raise "can't convert value '%s' to eoln delimited string"
def to_python (self, value, state):
class SOStringListCol (SOStringCol):
return [StringListValidator()] + super (SOStringListCol, self).createValidators()
class StringListCol (Col):
baseclass = SOStringListCol
Dr Paul-Michael Agapow: VieDigitale / Inst. for Animal Health