6 ms·
If you don’t use Django’s ORM or SQLAlchemy’s ORM, then do you really need to use Django? Like an adjacent commenter said, ORM is ok for simple blog websites.
by blackrock 6y ago
If you don’t use Django’s ORM or SQLAlchemy’s ORM, then do you really need to use Django?
Like an adjacent commenter said, ORM is ok for simple blog websites. But I can’t imagine using an ORM for complex data tables and relationships with normalized data.
- BiteCode_dev 6y agoI used the Django ORM for surprisingly complex applications I created a video streaming website, with 600k visitor days, that features tagging, categories, related vidéos, user upload, encoding queue, search with auto-completion and so on. It relies heavily on the ORM. Django migration system and db model generation also make it a very nice tool for data export/migration/exploration. The ORM provides a nice API, but above all, a standardized one, which lead the Django ecosystem to become so reach because of the assumptions the libraries could do, making you very productive. Now, one has to remember: - you can, and should by pass the ORM if you need it, writing raw SQL. Django let you do that. - plenty of things can end up be in a cache, using varnish, redis, etc. Plus a lot of things should be done in task queues anyway, not in the django views. So the cost of the ORM is rarely an issue. - complex data tables are sometimes better presented using SQL views, making the ORM model simple. As usual with coding, it's a matter of gain and cost, and the right answer is "it depends". But you can go very far, and very comfortably with this tools, as long as you don't fight against its nature. So yes, definitely use Django with the ORM. I am not advocating to use Django + SQLA, but rather contrast Django with Flask + SQLA.
- darkhorse13 6y ago>But I can’t imagine using an ORM for complex data tables and relationships with normalized data. Whenever I read a statement like this from someone, I always feel that they actually haven't thoroughly read the docs for Django's ORM. Can you give me one concrete complex example that you can't imagine doing with the ORM? Because 95% of the time, these "complex" models are trivially easy to pull off with the ORM (from my experience).
- ddorian43 6y agoDjango orm doesn't support composite primary keys.
- darkhorse13 6y agoFair enough. There is `unique_together` though, which you may look into.
- BiteCode_dev 6y agoThe beauty of the Django ecosystem, is that you have packages for everything: djangopackages.org E.G: https://github.com/Arisophy/django-compositepk-model https://github.com/Arisophy/django-compositepk-model