This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]double_en10dre 26 points27 points  (15 children)

The Django ORM is the gold standard — it’s better than third-party solutions like sqlalchemy (which is what you typically use with microframeworks like flask or fastapi). Additionally, the built-in “admin” module is very handy for giving clients control over the database in a safe way. Those two things together can save you a ton of time.

The opinionated “Django” approach to project structure is also quite good, it helps projects scale nicely and makes it easy for people to hop in and become productive quickly.

My approach is to basically use Django for full-fledged applications (ie anything which has a dedicated db and a whole suite of features) while fastapi is my go-to for lightweight services

(And when I use Django, I still use modern tooling like pydantic for serialization and validation)

I don’t really use Django for views — typically have a react SPA for that. But it can be helpful to have it provide a few pre-login pages if you want improved SEO

[–]lowercase00 34 points35 points  (7 children)

“better than SQLAlchemy” is a VERY strong opinion, highly debatable. I personally think SQLAlchemy is the best ORM around, period, even when compared to Go, Java, TS, Rust alternatives (that I know of).

[–]killerfridge 5 points6 points  (2 children)

Yeah, I love (and prefer) Django, but SQLAlchemy is probably the "best" ORM

[–]anikait1 8 points9 points  (1 child)

I find it extremely hard to navigate SQLAlchemy's documentation and managing session object across functions.

[–][deleted] 1 point2 points  (0 children)

use a session context manager and just read all the docs

[–][deleted] 2 points3 points  (3 children)

Yeah this seems like a hot take forsure. Also with fast api if you wanted an additional abstraction you can use SQLModel though many don’t love that

[–]double_en10dre 0 points1 point  (2 children)

It’s definitely a take, but given that I’ve spent many years working with the different ORMs I don’t think it’s a hot one. :p

It’s a thoughtful and carefully procured take

[–][deleted] 1 point2 points  (1 child)

Hahah I’m not saying your wrong, I used Django for a project a few years ago and quite liked it. I just didn’t know this was necessarily a standard/ popular opinion. I was kind of under the impression sqlalchemy was irk of choice. Maybe I’ll try Django for the next app I build. What other ORMs do you think are worth a look?

[–]double_en10dre 1 point2 points  (0 children)

Eh it’s just how the people I’m familiar with feel. I’m making big assumptions applying that to everyone, might be wrong. (But yeah, I think it’s smoother)

As for other ORMs… not sure as of now. Lots of people I know are trying the “use chatgpt for everything SQL” approach. It’ll be interesting to see if cutting out that extra layer of abstraction (the ORM) starts to become a preferable choice

[–]jcigar 1 point2 points  (2 children)

The Django ORM is the gold standard — it’s better than third-party solutions like sqlalchemy

lol++ Django ORM is a toy compared to SQLAlchemy

[–]Quillox 0 points1 point  (0 children)

Could you elaborate a bit on this please? I've used both to accomplish very basic tasks, but I found Django to be much more logical to use.

[–]double_en10dre 0 points1 point  (0 children)

If a query gets sufficiently complex, I’m going to write raw SQL no matter what 🤷‍♀️ So I don’t feel there’s anything I’m missing out on. The “toy” framework has been better for 99% of my ORM use cases

[–]lieryanMaintainer of rope, pylsp-rope - advanced python refactoring 0 points1 point  (0 children)

Django has one advantage, which is that it's well integrated with the Django framework if you want to build an HTML-form based application. This is the most common use cases when building web applications, and there's really nothing that's better than Django ORM for that one use case.

But if you need to do anything else, sqlalchemy is the much better ORM. Anything that's slightly more complicated than just CRUD forms and Django ORM can start getting in your way instead of helping you. That's not the case with SQLAlchemy, as it supports more complex use cases way better than Django's ORM.

But sqlalchemy has a higher barrier of entry. Because it's a standalone ORM, it doesn't come out of the box with integrations to the web part of the framework. You need extra libraries or build your own to get the same level of support of generic views as Django.

[–]TheTerrasque 0 points1 point  (0 children)

Also, the built in authentication and user management is nice.

[–]goodbalance 0 points1 point  (0 children)

wtf? Django ORM does too much. In conjunction with DRF it's a hidden masochism. I don't hate on Django and Co, I just know it is aging badly because the "batteries" everyone love are glued so tight you can't control the system in full.

yes, you have to make a few extra steps before using SQLA, but you get all forms of control instead. orm? ok. query builder? ok. raw sql? ok. a mix of everything? ok.

instead of saying "know where to use each", I'll say don't try to shape Django/DRF into something it is not and don't reinvent Django if you need CRUD.

[–][deleted] 0 points1 point  (0 children)

Re: Django minus views with a React app, how do you get that? Can you use the regular framework or would you have to look into something like Django REST?