我正在为我的 Django 视图流项目使用基于类的视图。但是我收到以下错误:
未找到“索引”的反向。“索引”不是有效的视图函数或模式名称
这是我的课程:
规则/流.py
class MyFlow(Flow):
"""
My App Flow
"""
process_class = models.MyProcess
start = flow.Start(
views.MyDetailView,
fields=["rule"],
task_title="New Task"
).Permission(
auto_create=True
).Next(this.end)
end = flow.End()
规则/urls.py
rule_urls = FlowViewSet(MyFlow).urls
urlpatterns = [
url(r'^rule/', include(rule_urls, namespace='rule')),
url(r'^(?P<pk>\d+)/mydetail/', MyDetailView.as_view(), {'flow_class': MyFlow, 'flow_task': MyFlow.start}, name='mydetail')
]
规则/模型.py
class SubRules(models.Model):
rule_id = models.AutoField(primary_key=True)
src_id = models.IntegerField()
src_description = models.CharField(max_length=160, blank=True)
class Meta:
db_table = 'sub_rules'
class EntRules(models.Model):
rule = models.OneToOneField(SubRules, primary_key=True, on_delete=models.CASCADE)
entitlement_code = models.IntegerField()
rule_approved = models.SmallIntegerField()
rule_approved_datetime = models.DateTimeField(null=True)
class Meta:
db_table = 'ent_rules'
class MyProcess(Process):
entrule = models.ForeignKey(EntRules, blank=True, null=True, on_delete=models.CASCADE)
class Meta:
permissions = (
('approve_ent_rules','Can approve ent_rules')
)
规则/forms.py
class MyDetailForm(forms.ModelForm):
class Meta:
model = EntRules
fields = [
'rule',
'entitlement_code',
]
def __init__(self, *args, **kwargs):
pk = kwargs.pop('rule_id', None)
super(MyDetailForm, self).__init__(*args, **kwargs)
sub_rule = SubRules.objects.get(rule_id=pk)
self.fields['rule'].queryset = sub_rule.objects.filter(rule_id=pk)
规则/视图/my_detail.py
class MyDetailView(StartFlowMixin, generic.UpdateView):
model = EntRules
template_name = 'rules/my_detail.html'
form_class = MyDetailForm
layout = Layout(
Fieldset('Rule Details',
Row('rule',),
Row('entitlement_code',),
)
)
def activation_done(self, form):
ent_rule = form.save()
self.activation.process.entrule = ent_rule
super(MyDetailView, self).activation_done(form)
def get_object(self):
return self.activation.process.entrule
def get_form_kwargs(self):
kwargs = super(MyDetailView, self).get_form_kwargs()
pk = int(self.kwargs['pk'])
kwargs['rule_id'] = pk
return kwargs
规则/模板/规则/my_detail.html
{% extends "base.html" %}
{% load material_form %}
{% block content %}
<form method="POST">
{% csrf_token %}
<div class="row">
{% form form=form %} {% endform %}
{{ activation.management_form }}
<div class="right">
<button type="submit" name="_start" class="btn">Submit</button>
</div>
</div>
</form>
{% endblock %}
你能告诉我这里可能是什么问题吗?
但是,如何将 sub_rule pk "^(?P\d+)" 传递给 startview,如下面的 URL 所示?
class MyFlow(Flow):
start = flow.Start(detail_view_class=MyDetailTaskView)
请指教。