[EMAIL PROTECTED] wrote:

>I have a bank statement for a particular account that I wish to display
>as an HTML table.
>I have a few statement attributes that come from my RDBMS. One in
>particular named 'amount' that can be a positive or negative float
>value. If its negative, it must show up in the debit column of the
>statement table otherwise must be displayed in the credit column.
>
>Now, this to me is very much view-based logic and not business logic. I
>say this because its only for the presentation purpose that we need to
>define debit and credit columns and not at business level. In business
>logic, amount is either positive or negative indicating crediting or
>debiting of the account respectively.
>  
>
Putting values in columns is indeed presentation logic. But deciding 
what exactly is "debit" or "credit" is a business one. Django templates 
pretty much require you to supply this exact distinction without 
"implementation details" (<0, >=0) even if these details are so small 
and obvious.

That said you can:

1. Create a list of dicts like [{'amount':0.5, 
'type':'credit'},{'amount':-0.5, 'type':'debit'}] and then in template 
use {% ifequal item.type 'credit' %}

2. In the Amount class create a method returning its type:

    class Amount():
        def of_type(self):
            return self.value<0 and 'debit' or 'credit'

3. Create a template filter doing the same thing

    def of_type(value, arg):
        return value<0 and 'debit' or 'credit'

and then using it like {% ifequal item|of_type 'credit' %}

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to