Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you like Django's ORM, it's perfectly simple to use it "standalone"; I've <a href="http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/" rel="noreferrer">written up several techniques for using parts of Django outside of a web context</a>, and you're free to use any of them (or roll your own).</p> <p>Shane above seems to be a bit misinformed on this and a few other points -- for example, Django <em>can</em> do multiple different databases, it just doesn't <em>default</em> to that (you need to do a custom manager on the models which use something other than the "main" DB, something that's not too hard and there are recipes floating around for it). It's true that Django itself doesn't do connection management/connection pooling, but personally I've always used external tools for that anyway (e.g., <code>pgpool</code>, which rocks harder than anything built in to an ORM ever could).</p> <p>I'd suggest spending some time reading up and possibly trying a few likely Google searches (e.g., the post I linked you to comes up as the top result for "standalone Django script") to get a feel for what will actually best suit your needs and tastes -- it may be Django's ORM isn't right for you, and you shouldn't use it if it isn't, but unfortunately there's a lot of misinformation out there which muddies the waters.</p> <p><strong>Editing to respond to Shane:</strong></p> <p>Again, you seem to be misinformed: SQLAlchemy needs to be configured (i.e., told what DB to use, how to connect, etc.) before you can run queries with it, so how is the fact that Django needs similar configuration (accomplished via your choice of methods -- you <strong>do not</strong> need to have a full Django settings file) any disadvantage?</p> <p>As for multiple DB support, you seem to be confused: the support is there at a low level. The query object -- not <code>QuerySet</code>, but the underlying <code>Query</code> object it will execute knows what DB it's connecting to, and accepts a DB connection as one of its initialization arguments. Telling one model to use one DB and another model to use another is as simple as setting up one method on a manager which passes the right connection info down into the <code>Query</code>. True, there's no higher-level API for this, but that's not the same as "no support" and not the same as "requires custom code" (unless you'd argue that configuring multiple DBs explicitly in SQLAlchemy, required if you want multiple DBs, is also "custom code").</p> <p>As for whether you end up <em>indirectly</em> using things that aren't in <code>django.db</code>, well, so what? The fact that <code>django.db</code> imports bits of, say, <code>django.utils</code> because there are data structures and other bits of code which are useful for more than just an ORM is fine as far as I'm personally concerned; one might as well complain if something has external dependencies or makes use of standard Python libraries instead of being 100% self-contained.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload