I'm having a problem figuring out where/when to call minimongo.configure() in my Pyramid app, to make sure that my minimongo class actually have a valid connection to the database.
The whole metaclass thing is causing the connection to be created when the module is imported and the class declaration is parsed, which is way before I've had a chance to read my setting files and get valid values for host and database.
It seems that I can't write an example like this in a single file:
import minimongo
class MyModel( minimongo.Model ):
"""Base MiniMongo model. all models should inherit from this one"""
class Meta:
"""Collection definition should go here."""
colection = "test"
def main():
minimongo.configure(
host = "mongo.ozoux.com",
database = "test"
)
a = MyModel()
a.name = "foo"
a.save()
if __name__ == '__main__':
main()
I get the following error:
File "test_minimongo.py", line 21, in <module>
class MyModel( minimongo.Model ):
File "minimongo/minimongo/model.py", line 49, in __new__
(name, options.host, options.port, options.database)
Exception: Model 'MyModel' improperly configured: localhost 27017 None
How exactly can I use minimongo with a deferred configuration call? I'd like to be able to define my models wherever I want, and as long as the call to configure happens before the class is instanciated, everything should be fine, no?
I'm having a problem figuring out where/when to call minimongo.configure() in my Pyramid app, to make sure that my minimongo class actually have a valid connection to the database.
The whole metaclass thing is causing the connection to be created when the module is imported and the class declaration is parsed, which is way before I've had a chance to read my setting files and get valid values for host and database.
It seems that I can't write an example like this in a single file:
I get the following error:
How exactly can I use minimongo with a deferred configuration call? I'd like to be able to define my models wherever I want, and as long as the call to configure happens before the class is instanciated, everything should be fine, no?