diff --git a/polls/forms.py b/polls/forms.py index 824b171..d1fd40b 100644 --- a/polls/forms.py +++ b/polls/forms.py @@ -2,10 +2,11 @@ import logging from typing import Any from django import forms +from django.apps import apps from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User -from .models import Question, Tag +from .models import Question class SignUpForm(UserCreationForm): @@ -68,10 +69,6 @@ class PollCreateForm(forms.ModelForm): widget=forms.Textarea( attrs={'class': large_box_style, 'placeholder': "Long description (Maximum 2000 characters)"})) - tags = forms.MultipleChoiceField( - choices=[(tag.id, tag.tag_text) for tag in Tag.objects.all()], - widget=forms.CheckboxSelectMultiple, - ) user_choice = forms.CharField( widget=forms.TextInput(attrs={'placeholder': 'Enter a choice'}), required=True @@ -80,6 +77,13 @@ class PollCreateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + Tag = apps.get_model('polls', 'Tag') + + tags = forms.MultipleChoiceField( + choices=[(tag.id, tag.tag_text) for tag in Tag.objects.all()], + widget=forms.CheckboxSelectMultiple, + ) + class Meta: model = Question fields = ['question_text', 'pub_date', 'end_date', 'short_description', 'long_description', 'tags'] diff --git a/polls/templates/polls/creation.html b/polls/templates/polls/creation.html index 7bdac54..660e86b 100644 --- a/polls/templates/polls/creation.html +++ b/polls/templates/polls/creation.html @@ -39,7 +39,7 @@
- + {{ form.tags }}
diff --git a/polls/templates/polls/search.html b/polls/templates/polls/search.html index 3eba8bd..a384185 100644 --- a/polls/templates/polls/search.html +++ b/polls/templates/polls/search.html @@ -35,9 +35,9 @@ {% if user.is_authenticated %} - + Sign out