第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Django:不支持的 CharField 查找“case_exact”或不允許加入該字段

Django:不支持的 CharField 查找“case_exact”或不允許加入該字段

慕斯王 2021-09-11 20:22:55
這是我的服務器上的 GET 請求。 HTTP GET /testPage/?persona_name=Aman&key_name=country&key_label=My+Country&key_value=India&Save=Submit 500在這個視圖的幫助下,我從 GET 請求中獲取值。def PersonaSave(request):    persona_name = request.GET.get('persona_name',)    persona_key = request.GET.get('key_name',)    persona_key_value = request.GET.get('key_value',)    persona_key_label = request.GET.get('key_label',)    persona_submit = request.GET.get('Save',)    return( persona_name , persona_key , persona_key_label , persona_key_value , persona_submit現(xiàn)在以下是我檢查具有給定角色名稱的對象是否存在的功能。如果它存在,那么我正在更新值,如果它是一個新的角色,那么我正在創(chuàng)建新的 testPersona 對象。def TestPageView(request):    x=PersonaSave(request)    persona_name = x[0]    persona_key = x[1]    persona_key_label=x[2]    persona_key_value=x[3]    persona_submit=x[4]    testPersonaName = TestPersonaName(name=persona_name)    testPersonaName.save()    if(persona_name is None and persona_key is None and persona_key_label is None and persona_key_value is None):        return render(request, 'dashboard/test_page.html') # Below is the function for updating testPersona .     elif TestPersonaName.objects.filter(name__case_exact=persona_name).exists():        testpersona = TestPersona.objects.get(name__case_exact=persona_name)        if testpersona.key == persona_key:            testpersona.label= persona_key_label            testpersona.value = persona_key_value            testpersona.save()#If persona with new name is detected then saving a new testPersona object.      testpersona=TestPersona(name=persona_name,key=persona_key,label=persona_key_label,value=persona_key_value)        testpersona.save()        return render(request,'dashboard/test_page.html')請您解釋一下為什么我會收到此錯誤以及如何消除此錯誤?提前致謝。
查看完整描述

3 回答

?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

改變這一行

 testpersona = TestPersona.objects.get(name__case_exact=persona_name)

 testpersona = TestPersona.objects.get(name__name__case_exact=persona_name)


查看完整回答
反對 回復 2021-09-11
?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

確切和模型字段名稱之間應該有2 個下劃線。


假設您正在匹配名為persona_name 的字段


elif TestPersonaName.objects.filter(persona_name__iexact=persona_name).exists():

    testpersona = TestPersona.objects.get(persona_name__iexact=persona_name)

iexact 無論大小寫敏感,都匹配值。


查看完整回答
反對 回復 2021-09-11
?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

最后,在這個問題上花了一整天之后,我能夠知道我在哪里做錯了。


在TestPersona 模型中,有一個字段“name”,它是模型TestPersonaName 的外鍵。這意味著TestPersonaName 的對象將被分配給TestPersona 的“name”字段。所以答案是:


def TestPageView(request):

    x=PersonaSave(request)

    persona_name = x[0]

    persona_key = x[1]

    persona_key_label=x[2]

    persona_key_value=x[3]

    persona_submit=x[4]


    if(persona_name is None and persona_key is None and persona_key_label is None and persona_key_value is None):


    # Since no paramteres are persent in GET request(i.e Nothing is filled in form), then we will simply render the blank form.

        return render(request, 'dashboard/test_page.html')


 #  Below is the function for updating testPersona . 


    elif TestPersonaName.objects.filter(name__iexact=persona_name).exists():

        testPersonaName_obj = TestPersonaName.objects.filter(name__iexact=persona_name) #Fetching an object from TestPersonaName model where name = persona_name

        testpersonaSet = TestPersona.objects.filter(name=testPersonaName_obj) #Passing testPersonaName_obj to 'name' field of TestPersona model because name is foreign key.

        for testpersona in testPersonaSet: #testPersonaSet is a QuerySet

            if testpersona.key == persona_key: #Checking whether persona with given key is already present or not


         # If TestPersona object with given name and give key is already present then we will update the details instead of making a new object.

                testpersona.label= persona_key_label 

                testpersona.value = persona_key_value

                testpersona.save()

                return render(request,'dashboard/test_page.html')    


#If persona with new name is detected then saving new objects of TestPersonaName and TestPersona object.

    testPersonaName = TestPersonaName(name=persona_name)

    testPersonaName.save() 

    testpersona(name=testPersonaName,key=persona_key,label=persona_key_label

                ,value=persona_key_value)

    testpersona.save()

    return render(request,'dashboard/test_page.html')


查看完整回答
反對 回復 2021-09-11
  • 3 回答
  • 0 關注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號