django - 来自两个不同表的依赖链下拉菜单的 Django 自动完成轻值错误
问题描述
我一直在阅读 DAL 教程,现在尝试将它实施到我的项目中,但不断得到
“ValueError:要解压的值太多(预期 2)[25/May/2020 18:42:17] “GET /wellsurfer/ajax/load_casing_weights?forward=%7B%7D HTTP/1.1”500 17744 “表格看起来像如下,如您所见,我无法制作表单来过滤结果,因此填充权重菜单 在此处输入图像描述
表格.py
class NewCasingDesignForm(forms.ModelForm):
od = forms.ModelChoiceField(queryset=CasingCatalogue.objects.order_by().distinct().values_list('size', flat=True))
class Meta:
model = CasingDesign
fields = (
'well', 'od', 'weight', 'pipeyield', 'connection','inner_diameter', 'set_depth', 'top_depth', 'type_csg_lnr',)
help_texts = {
'well': 'Select a well',
'od': 'unit, inches',
'weight': 'unit, lbs',
'pipeyield': 'unit, psi',
'connection': 'Type',
'inner_diameter': 'unit, inches',
'set_depth': 'What depth (feet) the pipe is set (shoe depth)',
'top_depth': '0 feet to indicate casing or a depth greater than 0 for liner',
'type_csg_lnr': 'Confirm if string is a casing or liner',
}
widgets = {
'well': forms.Select(attrs={
'class': 'form-control',
}),
'od': forms.Select(attrs={
'class': 'form-control',
}),
'weight': autocomplete.ListSelect2(url='wellsurfer:ajax_load_casing_weight', forward=['od']),
'inner_diameter': forms.NumberInput(attrs={
'class': 'form-control',
'placeholder': '8.835'
}),
'set_depth': forms.NumberInput(attrs={
'class': 'form-control',
'placeholder': '5000'
}),
'top_depth': forms.NumberInput(attrs={
'class': 'form-control',
'placeholder': '0'
}),
'type_csg_lnr': forms.Select(attrs={
'class': 'form-control',
}),
}
视图.py
def new_casing_design(request):
if request.method == 'POST':
form = NewCasingDesignForm(request.POST)
if form.is_valid():
newcasingdesign = form.save(commit=False)
newcasingdesign.created_by = request.user
newcasingdesign.created_at = timezone.now()
newcasingdesign.save()
return redirect('wellsurfer:index')
else:
form = NewCasingDesignForm()
return render(request, 'wellsurfer/create_new_casing_design.html', {'create_casing': form})
def load_casing_weight(request):
od = request.GET.get('od')
weight = CasingCatalogue.objects.filter(bodyod=od).distinct().values_list('nomweight', flat=True)
return weight
网址.py
from django.urls import path
from . import views
app_name = 'wellsurfer'
urlpatterns = [
path('', views.index, name='index'), # empty string # represents root of the app
path('wells/<name>/', views.well_details, name='well_details'),
path('wells/<name>/<run>/<run_id>', views.run_record, name='run_record'),
path('wells/<well_name>/<plan_or_survey_name>', views.plan_or_survey_view, name='plan_or_survey_view'),
path('search', views.search, name='search'),
path('new-operator/', views.new_operator, name='new_operator'),
path('new-asset/', views.new_asset, name='new_asset'),
path('new-pad/', views.new_pad, name='new_pad'),
path('new-well/', views.new_well, name='new_well'),
path('new-well-plan/', views.new_well_plan, name='new_well_plan'),
path('new-casing-design/', views.new_casing_design, name='new_casing_design'),
path('ajax/load_casing_weights', views.load_casing_weight, name='ajax_load_casing_weight'),
]
解决方案
推荐阅读
- database - 使用 Flutter 上的某些触发器使 webview 更改数据
- php - 如何在电子商务门户网站流量巨大的情况下保持库存
- python - plt.imshow TypeError:dtype对象的图像数据不能转换为float
- mysql - mysql信息_schema.tables的create_time、update_time
- python - 使用 Python 和 Regex 查找看起来像句子的文本
- python - 为什么 ctypes.memmove 对于不同大小的大小需要恒定的时间
- html - 在 div 底部时停止粘性滚动
- snowflake-cloud-data-platform - Linux SnowSQL [Errno 13] 权限被拒绝:'/home/snowsql_rt.log_bootstrap'
- javascript - 有没有办法使用 reader.onload return 来设置我的状态?
- salesforce - SalesForce 查询在查询编辑器中返回结果,但从 Lightning 组件中的 APEX 代码返回 null