-2

This is my edit.html code and during retrieving the values from database it shows only the text fields like value={{ i.full_name}} but when I am writing value={{ i.cv}}, value={{ i.status}}, value={{ i.gender}} it does not shows the value which needs to bed edited I have two choice fields and one file field.

this is my edit.html

<section class="site-section">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 mb-5">
        <h2 class="mb-4 text-center">Update Candidate Details</h2>
          
        <form method="POST" action="/update/ {{i.id}}/"  enctype="multipart/form-data" class="p-4 border rounded" onsubmit="myFunction()" >
        {%  csrf_token %}
          {% comment %} <input type="hidden" name="csrfmiddlewaretoken" value="UabxqpD8HGPOu1ZSFnIHAPbMtRgWBAnVHEs8bLDx0HnxN6uhG3LyYvZShvcx1ekn"> {% endcomment %}
          
          <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="full_name">Full Name :</label>
              <input type="text" class="form-control" value ={{ i.full_name}} name="full_name" id="id_full_name" placeholder="Enter First Name">
            </div>
          </div>   

          <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="recruiter_name">Recruiter Name :</label>
              <input type="text" class="form-control"  value ={{ i.recruiter_name }} name="recruiter_name" id="id_recruiter_name" placeholder="Enter Recruiter Name">
            </div>
          </div>     
  

          {% comment %} <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
            <label class="text-black" for="id_last_name">Last Name :</label>
              <input type="text" class="form-control" name="last_name" id="id_last_name" placeholder="Enter Last Name">
            </div>
          </div> {% endcomment %}
        
          <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="email">Email :</label>
              <input type="email" class="form-control"  value ={{i.email }} name="email" id="id_email" placeholder="Enter Email">
            </div>
          </div>

          <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="noticeperiod">Notice Period (in Days) :</label>
              <input type="text" class="form-control"  value ={{i.noticeperiod }} name="noticeperiod" id="notice_period" placeholder="Notice Period">
            </div>
          </div>

          <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="preferredlocation">Current Location :</label>
              <input type="text" class="form-control"  value ={{i.preferredlocation}} name="preferredlocation" id="preferred_location" placeholder="Enter Current Location">
            </div>
          </div>

            <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="expectedlocation">Expected Location :</label>
              <input type="text" class="form-control"  value ={{i.expectedlocation}} name="expectedlocation" id="expected_location" placeholder="Enter Multiple Locations seperated by comma">
            </div>
          </div>

            <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="currentctc">Current CTC (Per Annum) :</label>
              <input type="text" class="form-control"   value ={{i.currentctc }} name="currentctc" id="current_ctc" placeholder="Current CTC">
            </div>
          </div>

            <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="expectedctc">Expected CTC (Per Annum) : </label>
              <input type="text" class="form-control"  value ={{i.expectedctc }} name="expectedctc" id="expected_ctc" placeholder="Expected CTC">
            </div>
          </div>
          
           <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" for="status">Status : </label> </br>

              <select name="status" id="status" class="form-control"  value ={{i.status }}>
                <option value="CV Received">CV Received</option>
                <option value="Submitted to Client">Submitted to Client</option>
                <option value="Rejected">Rejected</option>
                <option value="Offered">Offered</option>
                <option value="Joined">Joined</option>
                <option value="Closed">Closed</option>
                <option value="Payment Received">Payment Received</option>
                
              </select>
              {% comment %} <input type="text" class="form-control" name="status" id="status1" placeholder="Enter Application Status"> {% endcomment %}
            </div>
          </div>

          <div class="row form-group">
            <div class="col-md-12 mb-3 mb-md-0">
              <label class="text-black" >Upload CV</label></br>
              <input type="file"  name="cv" id="cv1"   value ={{ i.cv}} >
            </div>
          </div>


      
          <div class="row form-group mb-4">
            <div class="col-md-12 mb-3 mb-md-0">
              <div class="form-check form-check-inline">
              
                <input class="form-check-input" type="radio" name="gender" id="male" value={{i.gender}}>
                
                <label class="form-check-label" for="male">Male</label>
              </div>
              <div class="form-check form-check-inline">
                <input class="form-check-input" type="radio" name="gender" id="female" value={{i.gender}}>
                <label class="form-check-label" for="female">Female</label>
              </div>
            </div>
          </div>
        
          <div class="row form-group">
            <div class="col-md-12">
              <input type="submit" value="Update" id ="submit" class="btn px-4 btn-primary text-white">

               {% comment %} <a href="{% url 'jobapp:jobconfirm' %}" class="btn btn-warning btn-block btn-lg">Sign Up</a> {% endcomment %}
            </div>
          </div> 

this is my views.py

#delete
def delete(request, id):
    i = ApplyForm.objects.get(id = id)
    i.delete()
    return redirect('account:dboard')

#edit
def edit(request, id):
    i = ApplyForm.objects.get(id = id)
    context = {
        'i' : i
    }
    return render(request, 'account/edit.html', context)
    
#update
def update(request, id):
    i = ApplyForm.objects.get(id = id)
    i.full_name = request.POST['full_name']
    i.email = request.POST['email']
    i.noticeperiod = request.POST['noticeperiod']
    i.preferredlocation = request.POST['preferredlocation']
    i.expectedlocation = request.POST['expectedlocation']
    i.currentctc = request.POST['currentctc']
    i.expectedctc= request.POST['expectedctc']
    i.recruiter_name = request.POST['recruiter_name']
    i.status = request.POST['status']
    i.gender = request.POST['gender']
    i.cv = request.FILES['cv']
    i.save()
    return redirect('account:dboard')

this is my models.py

class ApplyForm(models.Model):
    full_name = models.CharField(max_length=300)
    email = models.EmailField(max_length=300)
    noticeperiod = models.CharField(max_length = 300)
    preferredlocation = models.CharField(max_length=300)
    expectedlocation = models.CharField(max_length=300)
    currentctc = models.CharField(max_length=300)
    expectedctc = models.CharField(max_length=300)
    recruiter_name = models.CharField(max_length = 300, null=True)
    status = models.CharField(max_length = 300,  null=True, choices= CATEGORY_CHOICES )
    gender = models.CharField(max_length=10, choices=GENDER_CHOICES)
    cv = models.FileField(upload_to='') 

I want a solutions here

1.I cant retrieve the values of Upload cv, Gender , Status by doing value={{ i.cv}}, value={{ i.status}}, value={{ i.gender}} while the text fields are working fine I am getting the value that means I can display the value of full name with this value={{ i.full_name}} in my form but not the choice and file fields Where I am going wrong I dont know.

1 Answers1

0

for your Update function

replace:

i.full_name = request.POST['full_name']

with:

i.full_name = request.POST.get('full_name')

and you'll need to do it for all the fields, and the update should work

taha maatof
  • 1,862
  • 2
  • 9
  • 23
  • Other fields are working like the text fields only three fields are not working upload cv, gender, status two choice fields and one fiel field where i am uploading a pdf – Joy Kumar Chakraborty May 08 '21 at 06:01
  • check my html that if I am doing anything wrong or not – Joy Kumar Chakraborty May 08 '21 at 06:02
  • you have posted the identical post already. https://stackoverflow.com/questions/67438156/in-django-i-cant-retrieve-the-values-for-upload-cv-status-gender-in-the-edit-h?noredirect=1#comment119209799_67438156. Please follow and implement hints from there. Pleas try to be more specific by adressing one problem and posting only the related code part as otherwise it gets very difficult to help. Just to clarify again: you need to understand how the HTML tag 'radio' is used and on the other side how Django <% if %> tag is used and 3. how to use the django FileField and the object 'File'. – Razenstein May 08 '21 at 07:09