title: How to return int from select option value in plain html in django
body: <p>I have a plain html form which contains a select option, the select option value should return an int to be stored in the database.</p>
  
  <p>I have tried converting the value to int in the view but it still doesnt work.</p>
  
  <p>This is the ScrummyGoals Model</p>
  
  <pre class="lang-py prettyprint-override"><code>class ScrummyGoals(models.Model):
      user_name = models.ForeignKey(ScrummyUser, on_delete=models.CASCADE)
      #goal_status = models.ForeignKey(GoalStatus, on_delete=models.CASCADE)
      task = models.CharField(max_length=200)
      #task_target = models.CharField(max_length=30)
      target_name = models.ForeignKey(GoalStatus, on_delete=models.CASCADE, default=1, related_name="scrummygoals")
  
  
  
      def __str__(self):
          return self.task
  </code></pre>
  
  <p>This is the model from which I am populating the select options.</p>
  
  <pre class="lang-py prettyprint-override"><code>class GoalStatus(models.Model):
      target = models.CharField(max_length=100, choices=target, default="Week")
  
      def __str__(self):
          return self.target
  </code></pre>
  
  <p>This is the html form</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form action="" method="post"&gt;
       {% csrf_token %}
    &lt;div class="form-group"&gt;
      &lt;label for="task"&gt;Task&lt;/label&gt;
      &lt;input type="text" class="form-control" id="task" name="task"&gt;
    &lt;/div&gt;
       &lt;div class="form-group"&gt;
      &lt;label for="task"&gt;Goal&lt;/label&gt;
           &lt;select name="goal" class="form-control"&gt;
               {% for goal in goal %}
               &lt;option value='{{goal.id | to_int }}'&gt;{{goal.target}}&lt;/option&gt;
               {% endfor %}
           &lt;/select&gt;
  
    &lt;/div&gt;
    &lt;button type="submit" class="btn btn-primary"&gt;Create task&lt;/button&gt;
  &lt;/form&gt;
  
  </code></pre>
  
  <p>This is the view which I am getting the post request and saving to the database.</p>
  
  <pre class="lang-py prettyprint-override"><code>def user_add_task(request):
      goal = GoalStatus.objects.all()
      if request.method == 'POST':
          if request.POST.get('task') and request.POST.get('goal'):
              task = ScrummyGoals()
              task.target_name = int(request.POST.get('goal'))
              task.user_name = request.user.scrummyuser.id
              task.task = request.POST.get('task')
              task.save()
              return redirect('myapp:home')
      return render(request, 'myapp/user_add_task.html', {'goal':goal})
  
  </code></pre>
  
  <p>I expect the value of the select option to be an int e.g 1 not a string e.g "1".
  So I get this error: 
  Exception Type:     ValueError
  Exception Value:    </p>
  
  <p>Cannot assign "1": "ScrummyGoals.target_name" must be a "GoalStatus" instance.</p>