Permalink
Browse files

First rush of models. WIP

  • Loading branch information...
1 parent 1a719f5 commit c55cd73f1f3341c4744e8993d13147ee7a86d74d @chrisglass chrisglass committed May 8, 2011
Showing with 40 additions and 0 deletions.
  1. +40 −0 shop_multiplecurrencies/models.py
@@ -1,3 +1,43 @@
from django.db import models
+from shop.util.fields import CurrencyField
+from shop.models.productmodels import Product
# Create your models here.
+
+class Currency(models.Model):
+ name = models.CharField(max_length=255)
+ symbol = models.CharField(max_length=10) # Should be short
+ prefix = models.Boolean(default=False) # Should the symbol be prefixed?
+
+class Price(models.Model):
+ """
+ A class representing a Price. A price is made of a value (the numerical
+ part), and a currency. They are tied to a product.
+ """
+ # Product is polymorphic, so this is actually a key to Product subclasses
+ product = models.ForeignKey(Product)
+ value = CurrencyField()
+ currency = models.ForeignKey(Currency)
+
+ def __unicode__(self):
+ if self.currency.prefix:
+ return "%s%s" % (self.currency.symbol, self.value)
+ else:
+ return "%s%s" % (self.value, self.currency.symbol)
+
+
+class MultipleCurrencyMixin(object):
+ """
+ A mixin to add to your product subclasses to make them multi-currencies
+ aware.
+ """
+ def get_price(self):
+ pass # TODO: Use a default currency setting or something
+
+ def get_price_in_currency(self, symbol):
+ """
+ Returns the price for this product in the currency matching `symbol`
+ """
+ price = Price.objects.filter(product=self, currency__symbol=symbol)
+ if len(price):
+ price = price[0]

0 comments on commit c55cd73

Please sign in to comment.