Saturday, February 26, 2011

foreign key reference in the 'def' to calculate tax

I've got the following model. A product can be associated to one
region, which has its own taxes. I'd like to associate the tax to the
region and calculate it.

class TaxReference(models.Model):
region = models.CharField(max_length=100)
. . .
tax_multiplier = models.DecimalField(max_digits=3,
decimal_places=2)
def __unicode__(self):
return unicode(self.region)

class Product(models.Model):
title = models.CharField(max_length=100)
. . .
price = models.DecimalField(max_digits=10, decimal_places=2)
tax = models.ForeignKey(TaxReference)
def __unicode__(self):
return self.title
def taxedprice(self):
return self.price*TaxReference.tax_multiplier

The very last line of code is what I'm trying to accomplish.

How would I return the calculation to get the taxedprice, since the
tax_multiplier is in another table (but its a foreign key in Product)?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment