Live data from Hacker News

Taming the beast that is the Django ORM – An introduction

davidhang.com

11–20 of 144 posts

Re: Taming the beast that is the Django ORM – An introduction

#11

Django’s ORM is the first one that I ever spent a lot of time with. Throughout my career I’ve interacted with other ORMs from time to time. It wasn’t until I’d done that, that I realised, even though it’s not perfect, how fantastic the Django ORM is. I thought they’d all be that good, but no. I’ve read a lot of criticisms of ORMs, as I’m sure everyone else has. Some of them are certainly valid criticisms that are imm…

The awkward part is realizing Django has been this good for well over a decade. The core design hasn't (ever?) changed.

I started using Django on I think version 1.2 or 1.3 in 2011, back when it didn't have database migrations and you had to use a library like South for it. Even then, as an ORM/query language it was apparently better than what other languages have now.

Re: Taming the beast that is the Django ORM – An introduction

#12
post #5

Django’s ORM is the first one that I ever spent a lot of time with. Throughout my career I’ve interacted with other ORMs from time to time. It wasn’t until I’d done that, that I realised, even though it’s not perfect, how fantastic the Django ORM is. I thought they’d all be that good, but no. I’ve read a lot of criticisms of ORMs, as I’m sure everyone else has. Some of them are certainly valid criticisms that are imm…

I agree. Django's ORM is great because it handles the relationships well, where many ORMs barely do the object mapping part well. I'm rewriting a large Django project in Java (quarkus + jooq), because it's at the point where I need a type system now, but it still has a place in my heart.

Aren't Django models close enough to types?

Re: Taming the beast that is the Django ORM – An introduction

#13
post #5

Earlier quoted context omitted.

I agree. Django's ORM is great because it handles the relationships well, where many ORMs barely do the object mapping part well. I'm rewriting a large Django project in Java (quarkus + jooq), because it's at the point where I need a type system now, but it still has a place in my heart.

Aren't Django models close enough to types?

Nope. Python type hinting is far far from Java like types.

And yes, I guess OP has now a large system that needs types enforced by the system to reduce the friction in evolving the stack.

Re: Taming the beast that is the Django ORM – An introduction

#14
post #7

Django’s ORM is the first one that I ever spent a lot of time with. Throughout my career I’ve interacted with other ORMs from time to time. It wasn’t until I’d done that, that I realised, even though it’s not perfect, how fantastic the Django ORM is. I thought they’d all be that good, but no. I’ve read a lot of criticisms of ORMs, as I’m sure everyone else has. Some of them are certainly valid criticisms that are imm…

Django's ORM is acceptable - but I think Rails/ActiveRecord is superior albeit certainly more opinionated. Most likely just my personal bias speaking because Rails was the first web "framework" I cut my teeth on.

I think Django's ORM is really great but only as long as that's the first thing you have seen.

If you started from Rails and ActiveRecord, you're probably not be very appreciative of Django's ORM.

Re: Taming the beast that is the Django ORM – An introduction

#15
post #11

Django’s ORM is the first one that I ever spent a lot of time with. Throughout my career I’ve interacted with other ORMs from time to time. It wasn’t until I’d done that, that I realised, even though it’s not perfect, how fantastic the Django ORM is. I thought they’d all be that good, but no. I’ve read a lot of criticisms of ORMs, as I’m sure everyone else has. Some of them are certainly valid criticisms that are imm…

The awkward part is realizing Django has been this good for well over a decade. The core design hasn't (ever?) changed. I started using Django on I think version 1.2 or 1.3 in 2011, back when it didn't have database migrations and you had to use a library like South for it. Even then, as an ORM/query language it was apparently better than what other languages have now.

The design of the ORM changed substantially once, early in Django's history, when the "magic removal branch" landed. There are some notes on the new syntax that introduced here: https://code.djangoproject.com/wiki/RemovingTheMagic#Codecha...

That branch merged on May 1st 2006: https://www.djangoproject.com/weblog/2006/may/01/magicremova...

I've long found Django's commitment to not breaking too much at once inspiring. The release notes and upgrade guides are really solid.

Re: Taming the beast that is the Django ORM – An introduction

#16
post #13

Earlier quoted context omitted.

Aren't Django models close enough to types?

Nope. Python type hinting is far far from Java like types. And yes, I guess OP has now a large system that needs types enforced by the system to reduce the friction in evolving the stack.

What about using pydantic?

Re: Taming the beast that is the Django ORM – An introduction

#17

Django’s ORM is the first one that I ever spent a lot of time with. Throughout my career I’ve interacted with other ORMs from time to time. It wasn’t until I’d done that, that I realised, even though it’s not perfect, how fantastic the Django ORM is. I thought they’d all be that good, but no. I’ve read a lot of criticisms of ORMs, as I’m sure everyone else has. Some of them are certainly valid criticisms that are imm…

> I thought they’d all be that good, but no.

I had the "pleasure" to use Doctrine once. Never again !

Re: Taming the beast that is the Django ORM – An introduction

#18
post #13

Earlier quoted context omitted.

Nope. Python type hinting is far far from Java like types. And yes, I guess OP has now a large system that needs types enforced by the system to reduce the friction in evolving the stack.

What about using pydantic?

FWIW, one python project I'm working on uses an obscure Framework, and ORM. I was contemplating to convert it to FastAPI+Pydantic, however the amount of effort needed was no different than rewriting the whole project.

Re: Taming the beast that is the Django ORM – An introduction

#19
post #6

Django’s ORM is the first one that I ever spent a lot of time with. Throughout my career I’ve interacted with other ORMs from time to time. It wasn’t until I’d done that, that I realised, even though it’s not perfect, how fantastic the Django ORM is. I thought they’d all be that good, but no. I’ve read a lot of criticisms of ORMs, as I’m sure everyone else has. Some of them are certainly valid criticisms that are imm…

For me Django and ActiveRecord stand out as 2 good examples of what an ORM should be like. Both feel like they make the simple stuff super easy, the complex stuff figure outable, and the super hard stuff trivially possible with raw SQL and a decent mapping from that back to regular code. Although over the years my code trends more and more towards `.rawSql` or whatever equivalent exists. Even for the simple stuff. It…

Same here, but IMO it is related to skill and experience.

Once you get sufficiently familiar with some paradigm the training wheels can come off.

“Raw” SQL is already an abstraction. Over time all the implicit magic will get on your nerves. Trying to shoehorn two completely different worlds into one abstraction is not worth it: you get to learn today’s untransferable funky ORM syntax and idiosyncrasies while losing sight of the actual skill that matters long term which is SQL itself.

I concede however that handling of SQL, the field names, the relations, is annoying. But it’s core to the problem you are probably solving (some form of CRUD). Plumbing is annoying but as a plumber I’d say get used to it instead of wishing to be dancer.

I notice this in other aspects of my work as well. When I switched away trom desktop environment to terminal I had the same feeling. It’s easier, less hassle, less wonky abstractions, more direct. Completely counter to what popular culture is telling me.

Re: Taming the beast that is the Django ORM – An introduction

#20
post #15
post #11

Earlier quoted context omitted.

The awkward part is realizing Django has been this good for well over a decade. The core design hasn't (ever?) changed. I started using Django on I think version 1.2 or 1.3 in 2011, back when it didn't have database migrations and you had to use a library like South for it. Even then, as an ORM/query language it was apparently better than what other languages have now.

The design of the ORM changed substantially once, early in Django's history, when the "magic removal branch" landed. There are some notes on the new syntax that introduced here: https://code.djangoproject.com/wiki/RemovingTheMagic#Codecha... That branch merged on May 1st 2006: https://www.djangoproject.com/weblog/2006/may/01/magicremova... I've long found Django's commitment to not breaking too much at once inspiring…

I used Django a lot from about 2007 to 2010 and, then, went for several years without using it at all. When I came back to it, I was delighted to find that everything still worked like it was supposed to, just better. Congrats on getting it right on the first try. That's...not something that happens very often in software.
Post reply on HN