Your model declarations are very confusing for me, and seems to be running
around in circles. Very difficult to follow for me.
The logical relationships are not clear. So, how to arrive at the
'rebate_pct' and 'wac' as you actually intend, is a mystery in itself for
me.

If you have the relationships clear in your mind, then you access the
related data from a model instance like as mentioned in
https://docs.djangoproject.com/en/dev/topics/db/queries/#related-objects

Else, as suggested, you can go for raw sql queries, if the query itself is
getting too complex.


On Sat, Aug 6, 2011 at 12:19 AM, nixlists <nixmli...@gmail.com> wrote:

> On Fri, Aug 5, 2011 at 7:51 AM, bruno desthuilliers
> <bruno.desthuilli...@gmail.com> wrote:
> > Without more informations about your models (and specially the
> > relationships), it's going to be rather difficult. As a general
> > consideration, if your Claim model can access these other models thru
> > relationships, well you just have to follow the relationships. This is
> > basic Django ORM stuff, well explained in the FineManual.
>
> Hi
>
> I have:
>
> class Product(models.Model):
>    ndc = models.CharField(max_length=50)
>    product_name = models.CharField(max_length=50)
>    quantity = models.IntegerField()
>    ...
>
> class Pricing(models.Model):
>    ndc = models.ForeignKey(Product)
>    # wholesale acquisition cost
>    wac = models.DecimalField(max_digits=17, decimal_places=8)
>    ...
> class Contract(models.Model):
>    name =  models.CharField(max_length=100)
>    products = models.ManyToManyField(Product, through='ContractProduct')
>
> class ContractProduct(models.Model):
>     contract = models.ForeignKey(Contract)
>    ndc = models.ForeignKey(Product)
>     wac = models.ForeignKey(Pricing)
>    rebate_pct = models.DecimalField(max_digits=17, decimal_places=8)
>    admin_pct = models.DecimalField(max_digits=17, decimal_places=8)
>
> class Claim(models.Model):
>    contract = models.ForeignKey(Contract)
>    ndc = models.ForeignKey(Product)
>    quantity = models.IntegerField(blank=True, null=True)
>
> I need a view where for every row returned from Claim I make a
> calculation based on quantity from the Claim, rebate_pct and wac. Is
> it possible to write a model method that would access these fields
> from the other tables?
>
> Thanks.
>
> --
> 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.
>
>

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