Thanks again Karen.
On Aug 13, 7:40 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Thu, Aug 13, 2009 at 5:01 PM, neri...@gmail.com <neri...@gmail.com>wrote:
>
>
>
>
>
> > Hello,
>
> > Do I need t convert the value returned from Max() to an int, or am I
> > using it incorrectly? I'm getting this template error:
>
> > Caught an exception while rendering: (1064, "You have an error in your
> > SQL syntax; check the manual that corresponds to your MySQL server
> > version for the right syntax to use near ''id__max': '2'} )' at line
> > 1")
> > 1
>
> > from django.db.models import Max
>
> > def preview(request, template_name='listings/preview.html',
> > order_num=Order.objects.aggregate(Max('id'))):
>
> One problem here is that Order.objects.aggregate(Max('id')) is going to
> return a dictionary, not an integer. You never pull the integer value out
> of the dictionary so your subsequent attempt to pass that dictionary as a
> filter value results in invalid SQL.
>
> Also, note that that aggregate call is going to be evaluated only once, when
> the function is defined at import time. If you want that value to reflect
> Orders that have been created since the file containing this function was
> loaded, you need to move that code into the body of the function.
>
> Karen
>
> > num = order_num
> > user = request.user
> > listings = Listing.objects.filter
> > (order__customer__user__username=user)
> > gallery = Photo.objects.filter
> > (order__customer__user__username=user, order=num)
> > return render_to_response(template_name, { 'user': user,
> > 'listings': listings, 'order': num, 'gallery': gallery })
>
> > Thanks,
>
> > Jason
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---