8000 Field.type converted to method that casts the value when set · Issue #130 · Jaymon/prom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Field.type converted to method that casts the value when set #130
Open
@Jaymon

Description

@Jaymon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0