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)
pub_date = models.DateTimeField(default=timezone.now)
active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
Expand Down
3 changes: 3 additions & 0 deletions 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="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 Down