List Info

Thread: Returning a Queryset




Returning a Queryset
user name
2007-12-18 02:16:47
Hey guys

Is there a way to return a QuerySet object, when I make my
own custom
sql?

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


Re: Returning a Queryset
country flaguser name
Australia
2007-12-18 20:14:21

On Tue, 2007-12-18 at 00:16 -0800, Rufman wrote:
> Hey guys
> 
> Is there a way to return a QuerySet object, when I make
my own custom
> sql?

No. Part of the reason is that it's not particularly useful
in the
general case and very easy to get into trouble. A QuerySet
has a lot of
methods that can be called on it that modify the eventual
query. These
methods are almost useless after custom SQL has been run,
because we
don't want to have to try and work out what your custom SQL
was doing.

What I suspect you are needing (since you don't explain your
use-case,
I'm obviously guessing a little bit) is something that has a
few of the
QuerySet methods -- primarily being an iterator that returns
some kind
of Python object instances and maybe supports the caching
that QuerySets
do. There are (low-priority) plans to write something like
that so you
can run custom SQL and pass it a dictionary or some
functions that will
map result rows to a Python object and support the iterator
and cache.
Anything beyond that is probably not useful, but I'd be
interested in
hearing the use-case you're wanting to solve.

Malcolm

-- 
Two wrongs are only the beginning. 
http://www.pointy-s
tick.com/blog/


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


Re: Returning a Queryset
user name
2007-12-19 04:17:27
> but I'd be interested in
> hearing the use-case you're wanting to solve.
>

I'm using GROUP BY, so I need to use raw sql. I want to use
a
QuerySet, so that I can use the ForeignKey mapping and for
the sake of
consistency in the way I render things in the template.

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


Re: Returning a Queryset
country flaguser name
Australia
2007-12-19 04:34:18

On Wed, 2007-12-19 at 02:17 -0800, Rufman wrote:
> > but I'd be interested in
> > hearing the use-case you're wanting to solve.
> >
> 
> I'm using GROUP BY, so I need to use raw sql. I want to
use a
> QuerySet, so that I can use the ForeignKey mapping and
for the sake of
> consistency in the way I render things in the
template.

So what you really want is group-by support in Querysets,
which is
something for the future. This isn't the same as arbitrary
SQL returning
true QuerySets (which is hard/impossible for the reasons I
mentioned
previously).

Malcolm

-- 
For every action there is an equal and opposite criticism. 
http://www.pointy-s
tick.com/blog/


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


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )