I overstated the problem:a  ValuesQuerySet is not completely useless,
but you lose a lot of the functionality that you would otherwise have
with a QuerySet.

There is a incongruency between the ValuesQuerySet and the regular
QuerySet in that the dictionary contains only string representations
of the field values rather than the datatype-representation of the
fields themselves -- which is what you get with a QuerySet.  In
essence the ValuesQuerySet breaks the paradigm of the model from which
it is derived.  If you try to do anything remotely exotic with your
ValuesQuerySet you'll quickly bump into this.  The most obvious case
is where you have a foreign key data element in your model. Consider
the example of when the foreign key refers to a lookup label table.
Whereas a queryset will dereference the element's value to give the
string label of the of the element's value (i.e., the text from the
label table), the same behavour is not mimiced in the ValuesQuerySet,
there you only get the numerical value of the element.  As another
example, you'll note that it is impossible to access meta information
from the rows of a ValuesQuerySet (again because each row is just a
flat dictionary, rather than a representation of the model).



cheers,
james

On Sep 18, 5:22 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 9/19/07, James <[EMAIL PROTECTED]> wrote:
>
>
>
> > You matter-of-factly suggest that a ValuesQuerySet is as good as
> > QuerySet.  However, the ValuesQuerySet has some fundamental
> > limitations.  In particular, the ValuesQuerySet does not have
> > attributes corresponding to the fields in the QuerySet.  This makes a
> > ValuesQuerySet completely useless in a template -- quite unlike a
> > regular QuerySet.
>
> It was said matter-of-factly because it's true. How is ValuesQuerySet
> useless in a template? It returns a list of dictionaries; the template
> syntax can iterate over lists, and dictionary keys are one of the
> lookup schemes. As long as you're not referencing an attribute that
> isn't contained in the ValueQuerySet, moving from a QuerySet to a
> ValuesQuerySet shouldn't even require a change in template.
>
> Yours,
> Russ Magee %-)


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to