姜戈& Jquery:如何覆盖 FilteredSelectMultiple 中选择的值?

发布于 2024-12-11 16:24:40 字数 1243 浏览 0 评论 0原文

我正在制定工单。在工作订单中,您可以选择要使用的一组工具。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文