I have a strange problem with Satchmo (eCommerce solution built using
Django) with a field defined as a FloatField but is returned as an "str"
instead of a Decimal.

Here is an excerpt of the code:

class SubItem(models.Model):
    """
    The unique inventoriable item.  For instance, if a shirt has a size
and color, then
    only 1 SubItem would have Size=Small and Color=Black
    """
    item = models.ForeignKey(Item)
    def _get_fullPrice(self):
        price_delta = Decimal("0.0")
        for option in self.options.all():
            if option.price_change:
                price_delta += option.price_change
        return self.item.price + price_delta
    unit_price = property(_get_fullPrice)


class Item(models.Model):
    """
    The basic product being sold in the store.  This is what the
customer sees.
    """
    price = models.FloatField(max_digits=6, decimal_places=2,
help_text="Base price for this item")


In _get_fullPrice, self.item.price is returned as an str instead of a
Decimal and it crash due to the difference in type between
self.item.price and price_delta.

I'm running Satchmo from python manage.py runserver on a windows box
with python 2.4 both Django and Satchmo from trunk updated today and MySql.

The error returned is the following

Request Method:         GET
Request URL:    http://localhost:8000/shop/cart/
Exception Type:         TypeError
Exception Value:        cannot concatenate 'str' and 'Decimal' objects
Exception Location:
C:\DjangoProjects\satchmo_20061228\satchmo\..\satchmo\product\models.py
in _get_fullPrice, line 339

Can somebody help ?
I don't understand and can't find the mechanism by which the Django type
"FloatField" is converted to a Python Decimal.

If I understand well, str is a method of the Decimal class. I don't
understand why it is returned.

I don't know if I gave enough details for somebody to help, please tell
me if you need more information to help.

- Frederic



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to