I'm trying to optimize some queries I'm making, but I'm not sure how
to do it.
61 for t in items:
62 try:
63 t.price = t.user_item_rel_set.get
(user=u).payment_amount
64 except:
65 t.price = -1 * t.buyer_item_rel_set.get
(buyer=u).payment_amount
66 return items
67
user_item_rel_set is a m2m relationship between the User and Item
class. For every item, I look back at its m2m relationship model and
retrieve payment_amount. The only problem is, select_related()
doesn't grab the user_item_rel_set.all() when I query for the items
(where items=Item.objects.select_related().all() ). Is there anything
I can do to speed this up? It's *very* slow.
On 8 Lis, 18:06, Victor <psyco...@gmail.com> wrote:
> Hi,
> user_item_rel_set is a m2m relationship between the User and Item
> class. For every item, I look back at its m2m relationship model and
> retrieve payment_amount. The only problem is, select_related()
> doesn't grab the user_item_rel_set.all() when I query for the items
> (where items=Item.objects.select_related().all() ). Is there anything
> I can do to speed this up? It's *very* slow.
I'm not sure what you're trying to do, but what about: