English 中文(简体)
未显示正确计算值的模板
原标题:Template not showing correct calculated values

I am trying to display the total amount that each user would get in a table on my template. Now when I do print statements in my console, I get the correct values but then when I put {{ total_dollar_amount }} on my template, it only shows me the last value.

现在,我认为,我应该通过<代码>,总价值——美元——amount,但那就留下了一种错误,说精度值是 t的。

谁知道我失踪了?

意见。 y

def ABD_report(request, *args, **kwargs):
"""
This report will show all  In Trust For  investments in the system and display all relevant information
"""
from investments.models import Investment
from reports.forms import InTrustForm
context = {}
if request.POST:
    form = InTrustForm(request.agents, request.POST)
    if form.is_valid():
        agents = form.cleaned_data[ agents ]
        context[ selected_agents ] = agents
        investments = Investment.objects.filter(plan__profile__agent__in=agents, plan__ownership_type__code = "itf")
        for i in investments:
            #count all members in each plan
            count = i.plan.planmember_set.all().count()
            #take off the primary member of the account
            count -= 1
            if i.interestoption:
                if i.interestoption.short_label ==  AN :
                    pay_amt = i.pay_amount
                    total_amt = (pay_amt / count)
                    context[ total_dollar_amt ] = total_amt
            context[ counted ] = count
        context[ investments ] = investments
        context[ show_report ] = True
else:
    form = InTrustForm(request.agents)

context[ form ] = form

return render_to_response( reports/admin/abd_report.html , RequestContext(request, context))
最佳回答

<条码>context变量为字典;每个钥匙只能具有一个价值。 页: 1

如果你想通过<条码>(现称)和<条码>,总价位 每项投资的数值,您必须附在投资标上,而不是在<条码>中确定关键值:

for i in investments:
    #count all members in each plan
    count = i.plan.planmember_set.all().count()
    #take off the primary member of the account
    count -= 1
    if i.interestoption:
        if i.interestoption.short_label ==  AN :
            pay_amt = i.pay_amount
            total_amt = (pay_amt / count)
            # attach value to the investment
            i.total_dollar_amt = total_amt
    # attach value to the investment
    i.counted = count

Now in your template, you can loop through investments.

问题回答

<代码>context[总额_dollar_amt]每当转让在摊位中被击中时就被超写。 欲了解将转至模板的价值,请在<代码>前填写“编码”栏目。

从你的描述中看,我并不完全清楚,但我认为你需要通过一个字典清单,以便了解情况,例如<条码>[投资_数据]=[],然后在行文中,<条码>。 然后在模板中:

{% for inv_data in investments_data %}
    {{ inv_data.inv.name }} total: {{ inv_data.total_amt }}
{% endfor %}




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签