Question

I want to use the @after_insert decorator of Elixir, but i can't access the Session within the model. Since i have autocommit set to False, i can't commit any changes in the event handler. Is there any best practice how to deal with that?

The Code I used to build model, database connection etc. are mostly taken off the documentations.

The desired method:

class Artefact(Entity):
[...]
    @after_insert
    def make_signature(self):
        self.signature = '%s-%s' % (self.artefact_type.title.upper()[:3], self.id)

All the Session initialization is done in the init.py in the same directory.

When I then call:

Session.update(self)
Session.commit()

I get an error that Session is undefined. Any idea?

Was it helpful?

Solution

Have you imported Session?

from packagename import Session

at the top of your model file should do the trick. Packagename is the directory name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top