姜戈& Jquery:如何覆盖 FilteredSelectMultiple 中选择的值?
我正在制定工单。在工作订单中,您可以选择要使用的一组工具。
class WorkOrder( models.Model ):
job_type_choices = (
( '1', 'Mechanical' ),
( '2', 'Electrical' ),
( '3', 'Instrumentation' ),
)
tools = models.ManyToManyField( Equipment, related_name='tools', blank=True, null=True )
job_type = models.CharField( max_length=45, choices=job_type_choices )
现在,用户可以创建工作订单模板。
class WorkOrderTemplate( models.Model ):
job_type_choices = (
( '1', 'Mechanical' ),
( '2', 'Electrical' ),
( '3', 'Instrumentation' ),
)
tools = models.ManyToManyField( Equipment ) #set all the default tools here
job_type = models.CharField( max_length=45, choices=job_type_choices )
每次更改 job_type(一个下拉列表)的值时,您都会使用您选择的相同 job_type 加载您在工作订单模板中选择的所有工具。
我使用 FilteredMultipleChoice 小部件的小部件:
tools = ModelMultipleChoiceField(
queryset=Equipment.objects.all(),
widget=widgets.FilteredSelectMultiple( "Tools", is_stacked=False ),
required=False )
我知道如何覆盖简单文本输入的值,但我不知道在这种情况下如何覆盖所选值。为此,我使用了jquery。
提前致谢 :)
I'm making a work order. In a work order, you can choose set of tools that you'll use.
class WorkOrder( models.Model ):
job_type_choices = (
( '1', 'Mechanical' ),
( '2', 'Electrical' ),
( '3', 'Instrumentation' ),
)
tools = models.ManyToManyField( Equipment, related_name='tools', blank=True, null=True )
job_type = models.CharField( max_length=45, choices=job_type_choices )
Now, a user can create a work order template.
class WorkOrderTemplate( models.Model ):
job_type_choices = (
( '1', 'Mechanical' ),
( '2', 'Electrical' ),
( '3', 'Instrumentation' ),
)
tools = models.ManyToManyField( Equipment ) #set all the default tools here
job_type = models.CharField( max_length=45, choices=job_type_choices )
Everytime you change the value of the job_type, which is a dropdown list, you will load all the tools that you selected in the work order template with the same job_type you've chosen.
The widget I'm using FilteredMultipleChoice widget:
tools = ModelMultipleChoiceField(
queryset=Equipment.objects.all(),
widget=widgets.FilteredSelectMultiple( "Tools", is_stacked=False ),
required=False )
I know how to override the value of a simple textinput, but I have no idea how to override chosen values in this case. For that, I used jquery.
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论