1

我在我的一个数据表中遇到问题 - 单击表的 LinkAction 时,它不会将数据传递到相应的视图。当您选择更新现有网络记录时,我需要拥有与您所获得的体验相同的体验。在那里,当您单击“编辑”行操作时,相应的表单将填充该网络数据。就我而言,我有一个自定义仪表板/面板/选项卡/表格。因此,当我单击该表行中的“编辑”链接操作时,我确实可以显示我的表单,但它没有从行中传递任何数据。这是我的表和操作(tables.py):

class UpdateWorkload(tables.LinkAction):
    name = "update"
    verbose_name = _("Edit Workload")
    url = "update"
    classes = ("ajax-modal",)
    icon = "pencil"

class WorkloadsTable(tables.DataTable):
    name = tables.Column("name",
                         verbose_name=_("Name"))
    description = tables.Column("description", verbose_name=_("Description"))
    image = tables.Column("image", verbose_name=_("Image"))
    flavor = tables.Column("flavor", verbose_name=_("Flavor"))

    class Meta:
        name = "workloads_table"
        verbose_name = _("Workloads Table")
        table_actions = (CreateNewWorkload,
                         UpdateWorkload,
                         DeleteWorkload)
        row_actions = (UpdateWorkload, DeleteWorkload)

这是我的更新视图(views.py):

class UpdateView(forms.ModalFormView):
    form_class = project_forms.UpdateWorkload
    template_name = 'update_workload.html'
    context_object_name = 'workload'
    success_url = reverse_lazy('index')

这是我的表格(forms.py):

class UpdateWorkload(forms.SelfHandlingForm):
    name = forms.CharField(max_length="255", label=_("Workload Name"))
    description = forms.CharField(widget=forms.Textarea,
                                  label=_("Description"), required=False)
    image_choices = []
    images = forms.ChoiceField(label=_("Images"), choices=image_choices)
    flavor_choices = []
    flavors = forms.ChoiceField(label=_("Flavors"), choices=flavor_choices)

    def handle(self, request, data):
        try:
            # here we will need to call update on http://127.0.0.1:8000/workloads/ and pass the id
            workload = 0
            msg = _('Workload was successfully updated.')
            messages.success(request, msg)
            # return workload
        except Exception:
            msg = _('Failed to update Workload %s')
            redirect = reverse(self.failure_url)
            exceptions.handle(request, msg, redirect=redirect)

我该怎么做才能使这个表和视图将行数据传递给表单?

4

0 回答 0