title: How do I pass Foreign key value in views.py?
body: <p><a href="https://i.stack.imgur.com/0fRGi.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>How do I access savedata.project_detail in views.py?
  Each user will have as many projects as he wants. Each project will have one unique primary key. I wan to access that primary key in def checklist(request) function.
  I only get model attribute &quot;checked_value&quot; from html template. The other attribute &quot;project_detail&quot; should automatically fetch primary key pf model &quot;project&quot;. But I don't know how to fetch primary key of model project in def checklist function. If anyone can help here.</p>
  <p>Here is models.py</p>
  <pre><code>class project(models.Model):
      project_name = models.CharField(max_length = 20)
      date = models.DateField((&quot;Date&quot;), default=datetime.date.today)
      user = models.ForeignKey(User, on_delete=models.CASCADE)
  
  
  class check_done(models.Model):
      checked_value = models.CharField(max_length = 200)
      project_detail = models.ForeignKey(project, to_field=&quot;id&quot;, db_column=&quot;project_detail&quot;, on_delete=models.CASCADE)
  </code></pre>
  <p>Here is views.py</p>
  <pre><code>def show(request):
      log_user = request.user
      projects = project.objects.filter(user=log_user)
      return render(request, 'project.html',{'p':projects})
  
  @login_required(login_url='/login/')
  def add(request):
      if request.method == &quot;POST&quot;:
          data = request.POST['data']
          new = project(project_name = data, user=request.user)
          new.save()
          return render(request, 'addproject.html')
      else:
          return render(request, 'addproject.html')
  
  @login_required(login_url='/login/')
  def checklist(request):
      if request.method == &quot;POST&quot;:
              savedata = check_done()
              savedata.project_detail = ??
              print(savedata.project_detail)
              savedata.checked_value = request.POST.get('abc')
              savedata.save()
              return render(request, 'checklist.html')
              
      else:
          return render(request, 'checklist.html')
  </code></pre>