Saturday, June 30, 2012

Re: advantages and disadvantages of Raw sql queries in django

On Sat, Jun 30, 2012 at 1:33 AM, Mike Dewhirst <miked@dewhirst.com.au> wrote:
> I firmly believe in using the ORM for everything until i am forced to use
> handwritten SQL.

absolutely agree


> I could also argue against custom SQL because it contains business logic and
> i prefer to keep that all in one place, ie., in models in python code.

of course, when you have to use SQL, the best place to put it is in
the models file, either on the model itself or on a custom manager.
That way, if/when you modify the database representation, you don't
have to change other parts of the code.

Even when using the ORM, any complex query is a good candidate to be
encapsulated as part of the model. Ideally, the model should expose a
high level view of your data objects, not simply an easy to use view
of the database.

--
Javier

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment