我正在尝试SubmissionsListView
为 Wagtail 管理员子类化。我正在按照本教程和本教程中的说明进行操作。
这是我的代码:
class CustomSubmissionsListView(SubmissionsListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if not self.is_export:
# generate a list of field types, the first being the injected 'submission date'
field_types = ['user'] + [field.field_type for field in self.form_page.get_form_fields()]
data_rows = context['data_rows']
DocumentModel = get_document_model()
for data_row in data_rows:
fields = data_row['fields']
for idx, (value, field_type) in enumerate(zip(fields, field_types)):
if field_type == 'document' and value:
doc = DocumentModel.objects.get(pk=value)
url = reverse('wagtaildocument:edit', args=(doc.id,))
# build up a link to the image, using the image title & id
fields[idx] = format_html(
"<a href='{}'>{}</a>",
url,
doc.title,
value
)
return context
我得到的错误是:
File "/home/dave/sandbox/clients/devnw/devnw/web/products/models.py", line 161, in get_context_data
if not self.is_export:
AttributeError: 'CustomSubmissionsListView' object has no attribute 'is_export'
我无法弄清楚发生了什么。`is_export' 确实存在于父模块中。任何指针?