0

can anyone help?

I want to print some counts from the DB (total records where the complete field = true and another when it equals false.

What have I done wrong in the below?

Thanks

VIEWS

def task_count(request):
    completetasks = Todo.objects.filter(complete=True).count()
    incompletetasks = Todo.objects.filter(complete=False).count()
    return render(request, 'counts.html')

URLS

urlpatterns = [
    url(r'^$', views.todo, name='index'),
    url(r'^create/$', views.create_task, name='create'),
    url(r'^counts/$', views.task_count, name='counts'),

COUNTS.HTML

{% extends 'base.html' %}
{% block content %}
<br><br><br>
{% if user.is_authenticated %}

<div class="container">
        {% filter upper %}
<h3>Notes for task</h3>
{% endfilter %}

</div>
{{ completetasks }}

{% else %}
<h2><a href="/login">Login</a></h2>

{% endif %}
{% endblock %}

1 Answer 1

1

In your views file change like this

def task_count(request):
    completetasks = Todo.objects.filter(complete=True).count()
    incompletetasks = Todo.objects.filter(complete=False).count()
    context = {
        'completetasks': completetasks,
        'incompletetasks': incompletetasks
    }
    return render(request, 'counts.html', context)

Then in counts.html

{{ completetasks }}
{{ incompletetasks }}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.