python sql query in django

Bruno Desthuilliers bdesth.quelquechose at
Wed Feb 25 21:48:45 CET 2009

May a écrit :
> On Feb 24, 10:36 am, "Diez B. Roggisch" <de... at> wrote:
>>> Thanks for all your suggestions.  From what I've experienced in Django
>>> and now that I know a little more about how Python functions, I will
>>> probably use a combination of PHP and Django, instead of trying to get
>>> Python to do the web portion of my project.  Thanks again!
>> That sounds like the worst idea. Django's ORM is good when used from
>> within django, because of all the additional goodies like the admin
>> interface.
>> But if you are going to do the webfrontend using PHP, what part is left
>> for django? If it's only the ORM (for whatever you still use that
>> anyway), there are better alternatives - SQLAlchemy, and SQLObject, for
>> Python. They are more powerful and not interwoven with django.
>> If you are going to hand-code the interface in PHP, I fail to see though
>> why you don't do that in Django directly. You are not forced to use the
>> Admin-interface.
>> Diez
> Hello Diez,
> I think Django is fabulous for the admin-interface, a simple text
> search and template inheritance. 

And I think you really don't get what Django is good for.

> I will use Django for all of those.
> What I'm not getting an answer to and cannot find an example of is a
> complex search, where I have to retrieve data from multiple tables,
> combine the data, remove the duplicates, etc 

Django's ORM is mostly a wrapper above the db-api. It's intended to make 
most common db access a no-brainer, not to replace full-blown SQL for 
complex things. Now the good news is that you *still* can drop to a 
lower raw-sql level - the one you'd get using either PHP or Python's 
db-api - for more complex things. IOW, PHP won't buy you anything here.

>  The code that started this thread is only a small piece
> of the complex data retrieval I need to do.

The "code that started this thread" is a total no-brainer using Django 
(as you would know by now if you had reposted your question on django's 
group - or even just read the FineManual, where this use case is fully 
documented), and doesn't even require going down to raw sql.

>  PHP is great for writing
> complex SQL queries right in the HTML template

What the .... a complex SQL query has to do in a template anyway ??? 
Sorry, but what you're saying here is that PHP is great for writing 
unmaintainable spaghetti code. FWIW, even PHP coders are trying to get 
out of this kind of mess nowadays.

More information about the Python-list mailing list