1

I'm learning how to use Bulbs models, I have questions on Node classes initialization.

From the documentation:

from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime

class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    age = Integer()

How can I perform data manipulation before saving the data in the node?

Can I perform something like

class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    if name == "Bar":
        name = "Foo"

Or I have to override the Node init?

class Person(Node):

    element_type = "person"

    name = String(nullable=False)

    def __init__(self, name):
        if name == "Bar":
            self.name = "Foo"
Hrabal
  • 2,403
  • 2
  • 20
  • 30

1 Answers1

0

Override the model's _create() method.

See https://github.com/espeed/bulbs/blob/master/bulbs/model.py#L565

Also see 'Customizing Bulbs Models Example":

Is there a equivalent to commit in bulbs framework for neo4j

Community
  • 1
  • 1
espeed
  • 4,754
  • 2
  • 39
  • 51