What is the scope of the fget=
argument upon initialization of a Bulbs class property?
For instance when I am writing:
from bulbs.model import Node, Relationship
from bulbs.property import String
class foobar(Node)
element_type = "foobar"
fget_property = String(fget=some_method)
What some_method
should be to get for the fget_property to be properly defined? Should it perform some operation on the other class properties or can it also be a function of the relations that are liked to an instance of the class, for instance something calling self.outV(some_relation)
?
Here the value for
fget
should be a method name that returns a calculated value. The method name should reference a method defined in your Bulbs Model class, and the method should have no parameters.The
fget
method gets called every time you create/update/save the element to the database.See https://github.com/espeed/bulbs/blob/master/bulbs/model.py#L347
Bulbs uses a Python Metaclass to set the
fget
function as a Pythonproperty
on theModel
class
you are defining (not to be confused with the Bulbs databaseProperty
, such asString
in your example).See Python class property (little "p") vs Bulbs database Property (big "P")...
Here's how
fget
is set on the BulbsModel
you define:See https://github.com/espeed/bulbs/blob/master/bulbs/model.py#L97
For an overview of how Metaclasses work in Python, see:
"Metaclasses Demystified" http://web.archive.org/web/20120503014702/http://cleverdevil.org/computing/78/
What is a metaclass in Python?
UPDATE: Here is a complete working example of a model declaration using an
fget
method...And here's a full working example for how to use it...