Hacker News new | ask | show | jobs
by mixedbit 4747 days ago
Why Django model is not an ORM?
2 comments

I'm not sure what Andrew meant, but as I understand django doesn't have concept of ORM like, for example, SQLAlchemy.

What you can do in SqlAlchemy is, your business-objects could be not some inheritances from some "Model" class, but rather just pure python objects. So you'd implement your business-logic without any knowledge of database etc (ok, you'd use some abstract interface for querying those objects). Then, you describe your "models" as objects representing your database schema (and data structures inside it). It's not the same as your business-objects and can differ quite a bit. And at the end, you "map" one to another, so that ORM only comes in when you map your business-objects into your models.

I'm still not sure why django models are not ORM, maybe because there's no mapping (as I described) going on. Personally I'm fine with ORM termin for django models :)

The models system absolutely provides an ORM, what Andrew was (I assume) saying was that the models layer encompasses more (and less) than what some people mean when they say ORM. For example the models layer includes validation, and all sorts of other pieces of metadata, not just the mapping; and it doesn't include some of the things other people think ORMs mean like SQLAlchemy or Hibernate's concept of a session.