prom
prom copied to clipboard
Field.type converted to method that casts the value when set
It would be nice to have something like this:
class Field(BaseField):
def type(self, val):
if val is None: return val
val_type = self.instance_type
if issubclass(val_type, (int, float, bool)):
val = val_type(val)
return val
def fset(self, orm, val):
return self.type(val)
def iquery(self, query, val):
return self.type(val)
fset should get called after iget is called when pulling from the db, so I think that would cover all bases and make sure that the values are the correct type, this could be overridden in a project to allow customization.
You can't pass the orm
to it though because iquery
uses a Query instance instead of an Orm instance.