Django Datetime field question

Posted by Shehzad009 on Stack Overflow See other posts from Stack Overflow or by Shehzad009
Published on 2011-01-07T16:10:06Z Indexed on 2011/01/07 16:53 UTC
Read the original article Hit count: 207

Filed under:
|
|
|

Hello I have been having a problem with django while trying to work with datetime. In my webapp I have a table like so when I run server.

ID  Owing
1   -100   (All the same value)
2   -100
3   -100
.    .
.    .
.    .

It has in one column Invoice id and the other owing. One-one relationship as well. sow for example owing value for 1 is 100. Unfortunately, this is where it all goes wrong because throughout column (Owing), it is giving me the owing value for ID=1. I want each ID to give me their owing value.

Here is my view. I also wonder if I may need a for loop somewhere as well.

def homepage(request):
    invoices_list = Invoice.objects.all()
    invoice_name = invoices_list[0].client_contract_number.client_number.name
    invoice_gross = invoices_list[0].invoice_gross
    payment_date = invoices_list[0].payment_date
    if payment_date <= datetime.now():
        owing = invoice_gross
        if payment_date > datetime.now():
            owing = 0
        else: owing= 0
    return render_to_response(('index.html', locals()), {'invoices_list': invoices_list ,'invoice_number':invoice_number, 'invoice_name':invoice_name, 'invoice_gross':invoice_gross, 'payment_date':payment_date, 'owing': owing}, context_instance=RequestContext(request))

EDIT: Here is my template. The thing is the function owing is not in my models so saying {{invoices.owing}} wont work.

  {% for invoices in invoices_list %}
        <tr>
        <td>{{invoices.invoice_number}}</td>
        <td>{{invoices.invoice_contact}}</td>
    <td>{{invoices.client_contract_number}}</td>
        <td>{{invoices.payment_date|date:"d M Y"}}</td>
        <td>{{invoices.invoice_gross}}</td>
    <td>{{owing}}</td>
   {% endfor %} 

© Stack Overflow or respective owner

Related posts about django

Related posts about datetime