title: django table of model data; trying to save items selected from a list outside of the model
body: <p>I have the following model in a project:</p>
  
  <pre><code>class CarAssignment(models.Model):
      leg = models.ForeignKey(Leg, null=True, blank=True)
      driver = models.ForeignKey(Driver, null=True, blank=True)
      riders = models.ManyToManyField(Rider, null=True, blank=True)
  </code></pre>
  
  <p>I'm trying to create a page with a table where an admin user can edit the driver and riders items for all of the car assignments in a specific group. I can't use a formset because I also need to add data from another model, and because the choices in each list come from a different subset of riders and drivers, those that belong to a specific group. Driver is a select list and Riders is a multiselect list. </p>
  
  <p>I have successfully built the page and table to represent the data, with correctly working drop-down lists.  However, I can't figure out how to save the items.  Here's a specific problem scenario:</p>
  
  <p>for row 1 in the table (representing CarAssignment object #1), I pick a new driver from the list in the select dropdown.  I'm assigning custom name tags in the html to identify them, as follows:</p>
  
  <pre><code>&lt;option selected name="select.driver.{{ car_assignment.id }}"&gt;{{ driver }}&lt;/option&gt;
  </code></pre>
  
  <p>Then in the view, I'm trying to see if it matches anything, as follows:</p>
  
  <pre><code>        for car_assignment in CarAssignment.objects.filter(leg__in=legs):
              driver_tag = "select.driver." + str(car_assignment.id)
              if driver_tag in request.POST:
                  car_assignment.driver = driver
                  car_assignment.save()
  </code></pre>
  
  <p>The problem is that when it finds a matching driver tag, all it returns is a string of the First Name and Last Name.  I can't do the car_assignment.driver = driver because it's trying to equate a driver object to a string.</p>
  
  <p>I'm not sure how to do this.  I guess I could parse out the first and last names and try to match them against the Driver model to get the Driver objects I need, but that seems inefficient and possibly error-prone. </p>
  
  <p>Any help is appreciated (I'm a programming and Django newbie). Thanks.</p>