首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django自动完成来自两个不同表格的相关链接下拉菜单的灯值错误

Django自动完成来自两个不同表格的相关链接下拉菜单的灯值错误
EN

Stack Overflow用户
提问于 2020-05-26 07:56:16
回答 1查看 114关注 0票数 0

我一直在复习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

代码语言:javascript
复制
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

代码语言:javascript
复制
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

urls.py

代码语言:javascript
复制
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'),

]
EN

回答 1

Stack Overflow用户

发布于 2020-05-26 08:38:56

如果您想要JSON响应,那么应该返回JsonResponse

代码语言:javascript
复制
return weight

下面的内容

代码语言:javascript
复制
return JsonResponse(list(weight))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62012544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档