mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improved view for creating a new part parameter
- Hide the Part input - Reduce options based on parameters that already exist!
This commit is contained in:
parent
c68c79ea43
commit
15a42878db
@ -19,7 +19,7 @@ part_attachment_urls = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
part_parameter_urls = [
|
part_parameter_urls = [
|
||||||
url('^new/?', views.PartParameterCreate.as_view(), name='part-param-create'),
|
url('^new/', views.PartParameterCreate.as_view(), name='part-param-create'),
|
||||||
]
|
]
|
||||||
|
|
||||||
part_detail_urls = [
|
part_detail_urls = [
|
||||||
|
@ -1404,6 +1404,47 @@ class PartParameterCreate(AjaxCreateView):
|
|||||||
form_class = part_forms.EditPartParameterForm
|
form_class = part_forms.EditPartParameterForm
|
||||||
ajax_form_title = 'Create Part Parameter'
|
ajax_form_title = 'Create Part Parameter'
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
|
||||||
|
initials = {}
|
||||||
|
|
||||||
|
part_id = self.request.GET.get('part', None)
|
||||||
|
|
||||||
|
if part_id:
|
||||||
|
try:
|
||||||
|
initials['part'] = Part.objects.get(pk=part_id)
|
||||||
|
except (Part.DoesNotExist, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return initials
|
||||||
|
|
||||||
|
def get_form(self):
|
||||||
|
""" Return the form object.
|
||||||
|
|
||||||
|
- Hide the 'Part' field (specified in URL)
|
||||||
|
- Limit the 'Template' options (to avoid duplicates)
|
||||||
|
"""
|
||||||
|
|
||||||
|
form = super().get_form()
|
||||||
|
|
||||||
|
part_id = self.request.GET.get('part', None)
|
||||||
|
|
||||||
|
if part_id:
|
||||||
|
try:
|
||||||
|
part = Part.objects.get(pk=part_id)
|
||||||
|
|
||||||
|
form.fields['part'].widget = HiddenInput()
|
||||||
|
|
||||||
|
query = form.fields['template'].queryset
|
||||||
|
|
||||||
|
query = query.exclude(id__in=[param.template.id for param in part.parameters.all()])
|
||||||
|
|
||||||
|
form.fields['template'].queryset = query
|
||||||
|
|
||||||
|
except (Part.DoesNotExist, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return form
|
||||||
|
|
||||||
|
|
||||||
class CategoryDetail(DetailView):
|
class CategoryDetail(DetailView):
|
||||||
|
Loading…
Reference in New Issue
Block a user