如果我在forms.py 中将ID 作为静态值提供,则表单正在正确呈现,当我使用从表单调用中获得的 ID 时,它不会正确呈现
视图.py
def assetAddJsonView(request,pk):
form = AssetAddjsonForm(id = pk)
context = {
'form': form
}
return render(request, 'asset_add_json.html', context)
表格.py
from django_jsonforms.forms import JSONSchemaField
class AssetAddjsonForm(Form):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('id')
super(AssetAddjsonForm, self).__init__(*args, **kwargs)
type_json_schema = Types.objects.values_list('details').get(id=1) # details contains schema object
type_json_schema = list(type_json_schema)[0]
add_asset = JSONSchemaField(schema = type_json_schema, options = options)
而不是传递id=1我想传递我在self.request中得到的值
我引用了这个链接 Django app generate forms dynamic from JSON?
提前致谢