On Thu, Jul 21, 2011 at 11:11 PM, nixlists <nixmli...@gmail.com> wrote:

> On Thu, Jul 21, 2011 at 4:30 PM, Jani Tiainen <rede...@gmail.com> wrote:
> > ContractProduct.objects.all()
> > Following might work also (not sure, but is easy to test in shell for
> > example):
> > for c in Contract.objects.all():
> >     for cp in c.contractproduct_set.all():
> >         print c, cp.product, cp.rebate_pct
> > --
> > Jani Tiainen
>
> Thanks. This works but kind of confusing, and I am looking for an easy
> way to find rebate_pct given contract and product ids.
>

Something like this?

ContractProduct.objects.filter(contract__id=X,
product__id=Y).values_list('rebate_pct', flat=True)

or if you already have a contract:
contract.products.filter(product__id=Y).values_list('rebate_pct', flat=True)

or product:
product.contractproduct_set.filter(contract__id=Y).values_list('rebate_pct',
flat=True)


-- 
Marc

-- 
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.

Reply via email to