Commit bc315c56 authored by felix.herrmann's avatar felix.herrmann
Browse files

fix(startup): Fix the failing django/postgres startup by moving database query...

fix(startup): Fix the failing django/postgres startup by moving database query in form to __init__ function of DataSetEditForm. Now the choices query is also run everytime the form is called.
parent 23b50643
......@@ -146,11 +146,8 @@ class DataSetForm(ModelForm):
class DataSetEditForm(ModelForm):
categories_choices = list()
for category in Category.objects.all().order_by("name"):
categories_choices.append((category.id, category.name))
main_category = forms.CharField(required=False)
categories = forms.MultipleChoiceField(required=False, choices=categories_choices)
categories = forms.MultipleChoiceField(required=False, choices=[])
class Meta:
model = DataSet
......@@ -167,7 +164,6 @@ class DataSetEditForm(ModelForm):
helper.form_tag = False
helper.help_text_inline = False
helper.layout = Layout(
# HTML(ADD_EDIT_HEADING),
Div(
Div("title", css_class="col-md-12",),
Div("subtitle", css_class="col-md-12",),
......@@ -175,7 +171,6 @@ class DataSetEditForm(ModelForm):
HTML(
"<span ic-get-from='{% url 'core:load' %}' ic-trigger-on='load'></span>"
),
Div("categories", css_class="col-md-4",),
css_class="row",
),
HTML(REQ_FIELD),
......@@ -183,6 +178,18 @@ class DataSetEditForm(ModelForm):
Div(HTML(UPDATED_MSG),),
)
# init form at every request to update categories queried from db
def __init__(self, *args, **kwargs):
super(DataSetEditForm, self).__init__(*args, **kwargs)
self.fields["categories"] = forms.MultipleChoiceField(
required=False,
choices=[
(category.id, category.name)
for category in Category.objects.all().order_by("name")
],
)
# forms.ChoiceField(choices=[(category.id, category.name) for color in Color.objects.all()])
class DataSetImageUploadForm(ModelForm):
# TODO: updated image needs to be loaded at save
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment