Hi,
I think this is not the solution.
I do another example:

MODEL
------------
class Procedure(models.Model):
      ....
      total_income = models.DecimalField (
        default = 0,
        max_digits = 11,
        decimal_places = 4,
        verbose_name = _("Total Income"),
      )
      total_fee = models.DecimalField (
        default = 0,
        max_digits = 11,
        decimal_places = 4,
        verbose_name = _("Total Fee"),
      )
      ....
      def total_no_vat(self):
         total_no_vat -no= self.total_income + self.total_fee
         return format(total_no_vat, settings.DECIMAL_SEPARATOR, 2)

      def total(self):
          total = self.total_no_vat() * 1.21
          return format(total, settings.DECIMAL_SEPARATOR, 2)

type of self.total_no_vat is unicode and I cannot do other operations
on this field.
Thanks,
Vittorino


On 4 Feb, 10:15, Denis Darii <[email protected]> wrote:
> Hi Vittorino, this is happen because the model fields are automatically
> formatted by django considering your settings.DECIMAL_SEPARATOR, but in
> your total() you're simply return the sum of two Decimal()
>
> To solve this you can import format and pass the result of total() to it
> like:
>
> from django.conf import settings
> from django.utils.numberformat import format
> ...
>      def total(self):
>         total = self.total_income + self.total_fee
>         return format(total, settings.DECIMAL_SEPARATOR, 2)
>
> hope it helps! Have a nice weekend!
> Denis.
>
> On Sat, Feb 4, 2012 at 9:52 AM, Vittorino Parenti <
>
>
>
>
>
>
>
> [email protected]> wrote:
> > Hello,
> > i've a problem with number format localization. This is an example of
> > my model and admin:
>
> > MODEL
> > ------------
> > class Procedure(models.Model):
> >      ....
> >      total_income = models.DecimalField (
> >        default = 0,
> >        max_digits = 11,
> >        decimal_places = 4,
> >        verbose_name = _("Total Income"),
> >      )
> >      total_fee = models.DecimalField (
> >        default = 0,
> >        max_digits = 11,
> >        decimal_places = 4,
> >        verbose_name = _("Total Fee"),
> >      )
> >      ....
> >      def total(self):
> >         return self.total_income + self.total_fee
>
> > ADMIN
> > -----------
> > class ProcedureAdmin(dmin.ModelAdmin):
> >      list_display = (..., 'total_income', 'total_fee', 'total', ...)
>
> > output is:
>
> > ... | 35,22 | 9,28 | 45.50 | ...
>
> > with comma in first two cases and dot then.
> > How can I do?
> > Thanks in advance,
> > Vittorino
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to [email protected].
> > 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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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