Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion polls/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ChoiceInline(admin.TabularInline): # or admin.StackedInline for a differe
@admin.register(Poll)
class PollAdmin(admin.ModelAdmin):
list_display = ["text", "owner", "pub_date", "active", "created_at"]
search_fields = ["text", "owner__username"]
search_fields = ["text", "description", "owner__username"]
list_filter = ["active", 'created_at', 'pub_date']
date_hierarchy = "pub_date"
inlines = [ChoiceInline]
Expand Down
6 changes: 4 additions & 2 deletions polls/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ class PollAddForm(forms.ModelForm):

class Meta:
model = Poll
fields = ['text', 'choice1', 'choice2']
fields = ['text', 'description', 'choice1', 'choice2']
widgets = {
'text': forms.Textarea(attrs={'class': 'form-control', 'rows': 5, 'cols': 20}),
'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 3, 'cols': 20}),
}


class EditPollForm(forms.ModelForm):
class Meta:
model = Poll
fields = ['text', ]
fields = ['text', 'description']
widgets = {
'text': forms.Textarea(attrs={'class': 'form-control', 'rows': 5, 'cols': 20}),
'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 3, 'cols': 20}),
}


Expand Down
1 change: 1 addition & 0 deletions polls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Poll(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE)
text = models.TextField()
description = models.TextField(blank=True, default='')
pub_date = models.DateTimeField(default=timezone.now)
active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
Expand Down
2 changes: 1 addition & 1 deletion polls/templates/polls/add_poll.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ <h2>Create new poll</h2>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
5 changes: 4 additions & 1 deletion polls/templates/polls/endpoll.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<div class="row">
<div class="col-md-8 offset-sm-2">
<h3 class="mt-3 mb-3 text-center">Result for: {{ poll.text }}</h3>
{% if poll.description %}
<p class="text-center text-muted">{{ poll.description }}</p>
{% endif %}
<!-- progress bar -->
<div class="progress mt-3">

Expand All @@ -40,4 +43,4 @@ <h3 class="mt-3 mb-3 text-center">Result for: {{ poll.text }}</h3>

</div>
</div>
{% endblock content %}
{% endblock content %}
5 changes: 4 additions & 1 deletion polls/templates/polls/poll_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ <h1>Polls details page</h1>
{% endif %}
<hr>
<h2 class="mt-3 mb-3">{{ poll }}</h2>
{% if poll.description %}
<p class="text-muted mb-3">{{ poll.description }}</p>
{% endif %}
<form action="{% url 'polls:vote' poll.id %}" method="POST">
{% csrf_token %}
{% for choice in poll.choice_set.all %}
Expand All @@ -30,4 +33,4 @@ <h2 class="mt-3 mb-3">{{ poll }}</h2>

</div>

{% endblock content %}
{% endblock content %}
2 changes: 1 addition & 1 deletion polls/templates/polls/poll_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ <h2 class="text-center mt-3">Choices</h2>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
5 changes: 4 additions & 1 deletion polls/templates/polls/poll_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ <h3 class="mt-3 mb-3 text-center">Result for: {{ poll.text }}</h3>
{% else %}
<h3 class="mt-3 mb-3 text-center">"{{ poll.text }}" Has Ended Polling!</h3>
{% endif %}
{% if poll.description %}
<p class="text-center text-muted">{{ poll.description }}</p>
{% endif %}
<h3 class="mb-2 text-center">Total: {{ poll.get_vote_count }} votes</h3>
<!-- progress bar -->
<div class="progress mt-3 mb-2">
Expand All @@ -45,4 +48,4 @@ <h3 class="mb-2 text-center">Total: {{ poll.get_vote_count }} votes</h3>

</div>
</div>
{% endblock content %}
{% endblock content %}
8 changes: 6 additions & 2 deletions polls/templates/polls/polls_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ <h1 class="text-center mb-5">Welcome to polls List!</h1>

<ul class="list-group">
{% for poll in polls %}
<li class="list-group-item"><a href="{% url 'polls:detail' poll.id %}">{{ poll.text|truncatewords:5 }}
<li class="list-group-item">
<a href="{% url 'polls:detail' poll.id %}">{{ poll.text|truncatewords:5 }}
{% if not poll.active%}
<i class="fas fa-check-circle ml-2"></i>
{% endif %}
</a>
{% if poll.description %}
<br><small class="text-muted">{{ poll.description|truncatewords:10 }}</small>
{% endif %}
{% if request.user == poll.owner %}
{% if poll.active %}
<a href="{% url 'polls:end_poll' poll.id %}" data-toggle="tooltip" data-placement="top" title="End Poll"
Expand Down Expand Up @@ -75,4 +79,4 @@ <h1 class="text-center mb-5">Welcome to polls List!</h1>
</div>
</div>

{% endblock content %}
{% endblock content %}
1 change: 1 addition & 0 deletions seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def seed_polls(num_entries=10, choice_min=2, choice_max=5, overwrite=False):
p = Poll(
owner=random.choice(users),
text=fake.paragraph(),
description=fake.text(max_nb_chars=200),
pub_date=datetime.datetime.now()
)
p.save()
Expand Down