Open jhonatanTeixeira opened 5 years ago
Looks like you're missing the middleware to commit. You can use SQLAlchemyDBMiddleware from django-sorcery. Something simple like
class MyMiddleware(SQLAlchemyDBMiddleware):
db = session
and register that in MIDDLEWARES
django settings.
Whats the difference between this project and django-sorcery?
django-sorcery does django and sqlalchemy integrations, django-rest-witchcraft does drf integrations. django-sorcery is a dependency of django-rest-witchcraft as they mostly deal with similar things, like mapping model metadata to a model form or model serializer.
I would only add that you can use SQLAlchemyMiddleware
for your middleware. no need to subclass anything then. that will commit across all your databases. its also mentioned in sorcery readme https://github.com/shosca/django-sorcery/blob/37087369bbc070cccf11e388e88a2c2387259a61/README.rst#L315
@miki725 he can't actually, he's not using databases
and the django-sorcery config, he's got his own scoped session, which is fine as it is part of the use case. He just needs a middleware and that's the quickest way to get it.
ah yes. didnt pay close attention to the actual code example. I guess this could a great opportunity to advertise sorcery and its magical abilities 😄 sorcerified db allows for use models somewhat django-like with things like Model.objects.filter()
, etc. @jhonatanTeixeira check out the readme for more examples. and thanks for using the lib! 🎉
Yes!, you can declare sqlalchemy models with django-like syntax:
class Owner(db.Model):
query_class = OwnerQuery
id = db.IntegerField(autoincrement=True, primary_key=True)
first_name = db.CharField(length=50)
last_name = db.CharField(length=50)
see https://github.com/shosca/django-sorcery/blob/master/tests/testapp/models.py for more details.
Very nice, maybe i will do a PR improvig the documentation after i get it all working, i like django and i like sqlalchemy. I think this lib is going to be perfect for my new architecture.
I got a problem using this implementation. All insert queries happens on the console correctly. However, the commit is not being called and data never gets flushed into the database.
Am i missing something?