Skip to content

Commit 0fd824b

Browse files
authored
Merge pull request #38 from abhiram304/master
Dashboard Changes
2 parents d75c27d + 7ad13b2 commit 0fd824b

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ For detailed instructions, refer to Google's documentation on [OAuth 2.0](https:
165165
<img src="https://user-images.githubusercontent.com/19981097/51410442-dc7d0e80-1b8e-11e9-8f8e-18e6d7bb70fb.png" width="100%"</img>
166166
</div>
167167
168+
<h3>Dsahboard Page</h3>
169+
<div align="center">
170+
<img width="100%" alt="dashboard" src="https://github.com/devmahmud/Django-Poll-App/assets/17628879/46bd5f4d-b236-44c4-8636-2e171e2173e5">
171+
</div>
172+
168173
<h2>Author</h2>
169174
<blockquote>
170175
Mahmudul alam<br>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% extends 'base.html' %}
2+
3+
{% block content %}
4+
<div class="container">
5+
<div class="row">
6+
<div class="col-md-8 offset-sm-2">
7+
<h1 class="text-center mb-5"> Dashboard</h1>
8+
<div class="table-responsive"">
9+
<table class="table table-bordered table-striped">
10+
<thead class="thead-dark">
11+
<tr>
12+
<th>Poll Question</th>
13+
<th>Voters</th>
14+
</tr>
15+
</thead>
16+
<tbody>
17+
{% for poll in poll_data %}
18+
<tr>
19+
<td>{{ poll.question }}</td>
20+
<td>{{ poll.unique_voters }}</td>
21+
</tr>
22+
{% endfor %}
23+
</tbody>
24+
25+
</table>
26+
</div>
27+
</div>
28+
</div>
29+
</div>
30+
31+
{% endblock content %}

polls/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
views.choice_delete, name='choice_delete'),
1717
path('<int:poll_id>/', views.poll_detail, name='detail'),
1818
path('<int:poll_id>/vote/', views.poll_vote, name='vote'),
19+
path('dashboard/', views.dashboard, name='dashboard'),
1920
]

polls/views.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ def polls_list(request):
3939
}
4040
return render(request, 'polls/polls_list.html', context)
4141

42+
@login_required()
43+
def dashboard(request):
44+
polls = Poll.objects.all()
45+
poll_data = []
46+
47+
for poll in polls:
48+
unique_voters = Vote.objects.filter(poll=poll).values('user').distinct().count()
49+
poll_data.append({'question': poll.text, 'unique_voters': unique_voters})
50+
51+
context = {'poll_data': poll_data}
52+
return render(request, 'polls/dashboard.html', context)
53+
4254

4355
@login_required()
4456
def list_by_user(request):

templates/includes/navbar.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<li class="nav-item">
1414
<a class="nav-link" href="{% url 'polls:list' %}">Polls</a>
1515
</li>
16+
<li class="nav-item">
17+
<a class="nav-link" href="{% url 'polls:dashboard' %}">Dashboard</a>
18+
</li>
1619
{% endif %}
1720
</ul>
1821
<div class="navbar-nav ml-auto">
@@ -25,4 +28,4 @@
2528
{% endif %}
2629
</div>
2730
</div>
28-
</nav>
31+
</nav>

0 commit comments

Comments
 (0)