如何将列表从一个视图发送到另一个视图?
我尝试使用if (snapshot.hasData) {
_nameController.value = _nameController.value.copyWith(
text: snapshot.data,
);
}
发送request.session
,但出现错误。
material_id_list
def get_autotransactions(request):
material_id_list = []
slug = request.POST.get('slug')
for index in range(int(request.POST.get('count'))):
material_id_list.append(request.POST.get(f'material_id-{index}'))
request.session['material_id_list'] = material_id_list
return redirect(f'/management/inventorization/transactions/create/{slug}/')
def form(request, slug):
material_id_list = request.session['material_id_list']
extra = 1
if material_id_list:
extra = len(material_id_list)
TransactionItemFormset = modelformset_factory(TransactionItem, formset=TransactionItemBaseFormSet,
fields=('material', 'supplier', 'amount', 'price'), can_delete=True, extra=extra)
organization = Organization.objects.get(slug=slug)
queryset = TransactionItem.objects.none()
transactionItems = TransactionItemFormset(request.POST or None, queryset=queryset, slug=slug, material_id_list=material_id_list)
if transactionItems.is_valid():
tran_dict = {}
for tran_form in transactionItems:
if tran_form.is_valid():
instance = tran_form.save(commit=False)
if instance.supplier.id:
if instance.supplier.id not in tran_dict.keys():
form = TransactionForm()
tran = form.save(commit=False)
tran.organization = organization
tran.supplier = instance.supplier
tran.created_by = Profile.objects.get(user=request.user)
tran.status = TRANSACTION_STATUS.NEW
tran.save()
instance.transaction = tran
tran_dict[instance.supplier.id] = tran
else:
instance.transaction = tran_dict[instance.supplier.id]
else:
if instance.material.supplier.id not in tran_dict.keys():
form = TransactionForm()
tran = form.save(commit=False)
tran.organization = organization
tran.supplier = instance.supplier
tran.created_by = Profile.objects.get(user=request.user)
tran.status = TRANSACTION_STATUS.NEW
tran.save()
instance.transaction = tran
tran_dict[instance.material.supplier.id] = tran
else:
instance.transaction = tran_dict[instance.material.supplier.id]
instance.units = instance.material.material.unit
instance.remain = instance.amount
instance.save()
return redirect('management:inventorization:transactions:income')
return render(request, f'{BASE_TEMPLATE}/form.html', {
'transactionItems': transactionItems
})
不要专注于这些视图的细节,主要问题是如何将列表url(r'^get_autotransactions', views.get_autotransactions, name='get_autotransactions'),
url(r'^create/(?P<slug>\S+)/$', views.form, name='create',),
发送到名为material_id_list
的视图
我收到以下错误:
def forms