mirror of
https://github.com/Sosokker/ku-polls.git
synced 2025-12-19 05:24:05 +01:00
Use Lazy Import (get_model) To solve migration problem
It look like migrate occur at import time and that make error, i'm not sure what happen under the hood but I think this way fix it.
This commit is contained in:
parent
764c273757
commit
7db720598a
@ -2,10 +2,11 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.apps import apps
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from .models import Question, Tag
|
from .models import Question
|
||||||
|
|
||||||
|
|
||||||
class SignUpForm(UserCreationForm):
|
class SignUpForm(UserCreationForm):
|
||||||
@ -68,10 +69,6 @@ class PollCreateForm(forms.ModelForm):
|
|||||||
widget=forms.Textarea(
|
widget=forms.Textarea(
|
||||||
attrs={'class': large_box_style,
|
attrs={'class': large_box_style,
|
||||||
'placeholder': "Long description (Maximum 2000 characters)"}))
|
'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(
|
user_choice = forms.CharField(
|
||||||
widget=forms.TextInput(attrs={'placeholder': 'Enter a choice'}),
|
widget=forms.TextInput(attrs={'placeholder': 'Enter a choice'}),
|
||||||
required=True
|
required=True
|
||||||
@ -80,6 +77,13 @@ class PollCreateForm(forms.ModelForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*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:
|
class Meta:
|
||||||
model = Question
|
model = Question
|
||||||
fields = ['question_text', 'pub_date', 'end_date', 'short_description', 'long_description', 'tags']
|
fields = ['question_text', 'pub_date', 'end_date', 'short_description', 'long_description', 'tags']
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<label class="block text-gray-700 text-sm font-bold mb-2">Tags</label>
|
<label class="block text-gray-700 text-sm font-bold mb-2">Tags(Press Ctrl to select Multiple Tags)</label>
|
||||||
{{ form.tags }}
|
{{ form.tags }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -35,9 +35,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<button class="flex items-center whitespace-nowrap rounded-full border border-transparent bg-green-500 px-5 py-2 text-sm font-bold text-white transition duration-150 ease-in-out hover:scale-[101%] hover:bg-green-700 focus:bg-green-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 active:bg-green-900">
|
<a href="{% url "polls:create_poll" %}" class="flex items-center whitespace-nowrap rounded-full border border-transparent bg-green-500 px-5 py-2 text-sm font-bold text-white transition duration-150 ease-in-out hover:scale-[101%] hover:bg-green-700 focus:bg-green-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 active:bg-green-900">
|
||||||
New Poll
|
New Poll
|
||||||
</button>
|
</a>
|
||||||
<a href="{% url 'logout' %}"
|
<a href="{% url 'logout' %}"
|
||||||
class="flex items-center whitespace-nowrap rounded-full border border-transparent bg-red-600 px-5 py-2 text-sm font-bold text-white transition duration-150 ease-in-out hover:scale-[101%] hover:bg-red-700 focus:bg-neutral-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 active:bg-neutral-900">
|
class="flex items-center whitespace-nowrap rounded-full border border-transparent bg-red-600 px-5 py-2 text-sm font-bold text-white transition duration-150 ease-in-out hover:scale-[101%] hover:bg-red-700 focus:bg-neutral-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 active:bg-neutral-900">
|
||||||
<span>Sign out <span class="hidden sm:inline-block">😭</span></span>
|
<span>Sign out <span class="hidden sm:inline-block">😭</span></span>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user