我一直在复习DAL教程,现在正在尝试将它实现到我的项目中,但仍然得到
“HTTP: too make to unpack (expected 2) 25/May/2012018:42:17 "GET /wellsurfer/ajax/load_casing_weights?forward=%7B%7D ValueError/1.1”500 17744“表单如下所示,正如您所看到的,我无法使表单过滤结果,因此权重菜单填充了enter image description here
forms.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',
}),
}views.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 weighturls.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'),
]发布于 2020-05-26 08:38:56
https://stackoverflow.com/questions/62012544
复制相似问题