I'm trying to filter some objects on a queryset, field on what I'm trying is a Decimal...
model:
class CheckingAccount(models.Model):
owner = models.ForeignKey(Owner)
name = models.CharField(max_length=50, blank=False)
description = models.CharField(max_length=50, blank=True)
datetime = models.DateTimeField(default=datetime.now, blank=False)
currency = models.ForeignKey(Currency)
balance = models.DecimalField(max_digits=20, decimal_places=6)
def __unicode__(self):
return unicode(self.balance)
form:
def clean(self):
message = self.cleaned_data['acquisition_value']
ow = Owner.objects.get(user_id=self.request.user.id)
ca = CheckingAccount.objects.filter(balance=self.cleaned_data['checkingaccounts'])
The error I'm getting is:
Exception Value:
Cannot convert to Decimal
Any idea?
It might go wrong for several reasons, depending on cleaned_data returned value.
First - what if cleaned_data- fails and returns and exception or something like that ? your filter won't work :( Second - It might be a decimal casting issue.
IMHO Do not use cleaned_data in the filter. Do your clean elsewhere, and filter with clear easy decimal number in the clean method.