2

The docs say to put this somewhere:

from sqlalchemy import event
from colanderalchemy import setup_schema
event.listen(mapper, 'mapper_configured', setup_schema)

Where should this go in Pyramid? Should I be using Pyramid events instead of SQLAlchemy's?

When I tried putting it at the top of the models.py file, it complained about mapper not existing; should I still be using that?

Rob Grant
  • 7,239
  • 4
  • 41
  • 61

2 Answers2

1

You need to use the SQLAlchemy events as they tell what is happening inside the SQLAlchemy (they do not relate to the pyramid events at all).

The documentation for the ColanderAlchemy is confusing; what they call for a mapper here is your model class (it is not a mapper).

Thus in your models you should be doing something like:

class MyModelClass(Base):
    ...

event.listen(
    MyModelClass,
    "mapper_configured",
    setup_schema)
  • 1
    This will be improved in the documentation [shortly](https://github.com/stefanofontanelli/ColanderAlchemy/pull/82) once merged. Feel free to contribute fixes like this to the code. You can suggest other improvements too! – davidjb Apr 06 '15 at 22:42
1

The test suite shows it working like this:

from sqlalchemy import event
from colanderalchemy import setup_schema
from sqlalchemy.orm import mapper

event.listen(mapper, 'mapper_configured', setup_schema)

Please let me know if that fixes it for you and I can go update the documentation accordingly.

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82
  • Yeah that seems to work. Thanks. The problem with the docs is (other than that import issue) that I don't know what to put next; i.e. I'm trying to use pyramid, sqlalchemy and deform for the first time. Before I get too far I now have to learn colander. Then to speed _that_ up I now have to learn colanderalchemy. It'd be really helpful if the colanderalchemy docs (as colanderalchemy is the most specialised of the components) just said how to register the models (done) and then what to put in my view_config to get a deform form into a template, all working, and then validate the response. – Rob Grant Apr 11 '15 at 13:51
  • You may want to look at `pyramid_deform`. I found it too restrictive for my uses, but it makes for an easy way to incorporate deform into pyramid. – Tim Tisdall Apr 28 '15 at 15:32