diff --git a/InvenTree/InvenTree/forms.py b/InvenTree/InvenTree/forms.py index a0fcd9979d..3038a1cd7f 100644 --- a/InvenTree/InvenTree/forms.py +++ b/InvenTree/InvenTree/forms.py @@ -201,28 +201,25 @@ class ColorThemeSelectForm(forms.ModelForm): class SettingCategorySelectForm(forms.ModelForm): """ Form for setting category settings """ - name = forms.ChoiceField(required=False) + category = forms.ModelChoiceField(queryset=PartCategory.objects.all()) class Meta: model = PartCategory fields = [ - 'name' + 'category' ] def __init__(self, *args, **kwargs): super(SettingCategorySelectForm, self).__init__(*args, **kwargs) - # Populate category choices - self.fields['name'].choices = [('', '-' * 10)] + PartCategory.get_parent_categories() - self.helper = FormHelper() # Form rendering self.helper.form_show_labels = False self.helper.layout = Layout( Div( - Div(Field('name'), + Div(Field('category'), css_class='col-sm-6', - style='width: auto;'), + style='width: 30%;'), Div(StrictButton(_('Select Category'), css_class='btn btn-primary', type='submit'), css_class='col-sm-6', style='width: auto; padding-left: 0;'), diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index c59b0cdcdd..e61e2d497c 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -765,7 +765,7 @@ class SettingCategorySelectView(FormView): category = self.request.GET.get('category', None) if category: - initial['name'] = category + initial['category'] = category return initial @@ -778,11 +778,9 @@ class SettingCategorySelectView(FormView): form = self.get_form() if form.is_valid(): - category = form.cleaned_data['name'] - context = self.get_context_data() - context['category'] = category + context['category'] = form.cleaned_data['category'] return super(SettingCategorySelectView, self).render_to_response(context) diff --git a/InvenTree/templates/InvenTree/settings/category.html b/InvenTree/templates/InvenTree/settings/category.html index d5e27d79a7..d17efd9c9a 100644 --- a/InvenTree/templates/InvenTree/settings/category.html +++ b/InvenTree/templates/InvenTree/settings/category.html @@ -14,7 +14,9 @@
{% csrf_token %} {% load crispy_forms_tags %} - {% crispy form %} +
+ {% crispy form %} +
{% if category %} @@ -35,10 +37,14 @@ {% block js_ready %} {{ block.super }} -{% if category %} + $(document).ready(function() { + attachSelect('#category-select'); + }); + +{% if category %} $("#param-table").inventreeTable({ - url: "{% url 'api-part-category-parameters' category %}", + url: "{% url 'api-part-category-parameters' category.pk %}", queryParams: { ordering: 'name', }, @@ -74,7 +80,7 @@ $("#new-param").click(function() { - launchModalForm("{% url 'category-param-template-create' category %}", { + launchModalForm("{% url 'category-param-template-create' category.pk %}", { success: function() { $("#param-table").bootstrapTable('refresh'); }, @@ -84,7 +90,7 @@ $("#param-table").on('click', '.template-edit', function() { var button = $(this); - var url = "/part/category/{{ category }}/parameters/" + button.attr('pk') + "/edit/"; + var url = "/part/category/{{ category.pk }}/parameters/" + button.attr('pk') + "/edit/"; launchModalForm(url, { success: function() { @@ -96,7 +102,7 @@ $("#param-table").on('click', '.template-delete', function() { var button = $(this); - var url = "/part/category/{{ category }}/parameters/" + button.attr('pk') + "/delete/"; + var url = "/part/category/{{ category.pk }}/parameters/" + button.attr('pk') + "/delete/"; launchModalForm(url, { success: function() {