
I do not like Django. I do not like Django ORM, Django templates, Django forms and many more things in Django. But Django has a definite advantage - many use Django, almost any python programmer is familiar with django. Therefore, we have to put up with the shortcomings of this framework, but no one bothers to make life easier for you, using really good python libraries, such as SQLAlchemy.
What is better in SQLAlchemy than in Django ORM? This is the main question I hear from Django guys
1 , and I have an answer to it - SQLAlchemy can express any SQL query (well, 80-90%), unlike Django ORM, in which only very simple things can be expressed.
And in some Django projects there is a need for complex queries that the standard ORM is unable to. Conditionally suppose that at the time of the project creation it was believed that the Django ORM would be enough. For the solution, you can write pure SQL or use SQLAlchemy. I am in favor of the second approach, since pure SQL does not lend itself well to DRY-fikatsii.
')
What are the disadvantages when using SQLAlchemy? It is necessary to describe the data structure for this library separately, since SQLAlchemy and Django ORM are not compatible, and their creators did not have such a plan. You can also try to build a data model for the structure of the database. It is also an option, but subtle moments emerge when the actual database is not yet available. I went the other way and built a structure on a jango model in my Aldjemy project.
To use, you just need to add `aldjemy` to the end of INSTALLED_APPS, and aldjemy will go through all the models and add the attribute` sa` to them.
Try, run ./manage.py shell_plus and enter:
User.sa.query.join(User.sa.user_groups).join(User.sa.user_groups.property.mapper.class_.group).filter(Group.sa.name=="GROUP_NAME")
, join- ? , SQLA, SQLA join- . , SQLA ? ! SQLA , , , — , , .
github.
PyPi:
pip install aldjemy
1. Django guys , Django. — Dj-.
: But aldjemy is not positioned as Django ORM drop-in replacement. Its helper for special situations.,
habrahabr.ru/blogs/python/128052/#comment_4231276