Click here to Skip to main content
15,393,377 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
It shows error in
pd=User.objects.get(id=user_id)


What I have tried:

views.py
Python
def editConsultant(request): 
    if request.method=='POST':
        name=request.POST.get('name')
        phone=request.POST.get('phone')
        email=request.POST.get('email')
        user_id=request.POST.get('user_id')
        status=request.POST.get('status')
        role=request.POST.get('role')
        engagements=request.POST.getlist('engagement')
        if engagements!=[]:
            
 
engagements=Engagement.objects.filter(engagementName__in=engagements).values_list('id',flat=True)
            pd=User.objects.get(id=user_id)
            k=pd.engagement.all().values_list('id',flat=True)
            if k:
                pd.engagement.remove(*k)
            pd.engagement.set(engagements)
            pd.save()
         j=User.objects.filter(id=user_id)
         j.update(status=status,role=role,first_name=name,phone=phone,email=email)
         return redirect('listconsultant')


Html

Add
<label>Account</label>
<span style="color:#ff0000">*</span>
<select  placeholder="Engagement" name="engagement" {% if userdetails %} value={{userdetails.Engagement}} {% endif %} class="dropdown-item">
    <option value="None">---Select Account------</option>
    {% for i in engagement %}
        <option id="parentclientId" value="{{i.engagementName}}">{{i.engagementName}}</option>
    {% endfor %}
    </select>
</div>


Edit
<div class="form-group">
                                <label>Account</label>
                                <select  placeholder="Engagement"class="dropdown-item" name="engagement" id="parentclientId"  >
                                    <option disabled="true">New Acc</option>
                                    {% for i in engagement %}
                                        <option value="{{i.id}}">{{i.engagementName}}</option>
                                    {% endfor %}    
                                </select>                                  
                                </div>
Posted
Updated 12-May-22 21:26pm
v4
Comments
Richard MacCutchan 11-May-22 4:17am
   
The message is telling you that user_id does not contain any information.
Member 15629421 13-May-22 3:27am
   
Can I know the error.
Richard MacCutchan 13-May-22 4:39am
   
I told you in my previous message: the user_id field is blank.
Member 15629421 13-May-22 9:47am
   
The database shows it is not blank
Richard MacCutchan 13-May-22 9:49am
   
The database can show what wants to, that has nothing to do with the code above. You need to use your debugging tools to find out why it is blank inside this part of your application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900