title: Inserting into model from controller - Odoo 10
body: <p>I need to create a form in my Odoo website so external users can register for a newsletter that is sent from my Odoo. So far I have created a website template and a controller. Thus far I have managed to display the form and do a Post as well as preload some additional many2many fields I need to fill the form but the data is not saved to the database when I hit submit. I have seen the website_portal and website_hr_recruitment models that have forms for people to fill out but I can't figure out where is the data saved and how it is done.</p>
  
  <p>I include the following code from my own controller for reference:</p>
  
  <p>My controller:</p>
  
  <pre><code>@http.route('/contact/register', type='http', auth='public', website='true')
  def register(self, redirect=None, **post):
  
      areas_interest = request.env['iica_contacts.area_interest'].sudo().search([])
      topics_interest = request.env['iica_contacts.topic_interest'].sudo().search([])
      products_interest = request.env['iica_contacts.products_interest'].sudo().search([])
      countries = request.env['res.country'].sudo().search([])
  
      if post:
          return request.redirect('/contact/register/success')
  
      values = {
          'areas_interest' : areas_interest,
          'topics_interest' : topics_interest,
          'products_interest' : products_interest,
          'countries' : countries,
      }
  
      return request.render("iica_contacts.register", values)
  </code></pre>
  
  <p>My Template:</p>
  
  <pre><code>&lt;template id="register"&gt;
  &lt;t t-call="website.layout"&gt;
    &lt;t t-set="title"&gt;Register&lt;/t&gt;
    &lt;form action="/contact/register" method="post"&gt;
      &lt;input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/&gt;
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
            &lt;div class="col-md-6 form-group"&gt;
              &lt;label for="first_name"&gt;First name:&lt;/label&gt;
              &lt;input type="text" name="first_name" class="form-control" t-att-value="first_name" /&gt;
            &lt;/div&gt;
            &lt;div class="col-md-6 form-group"&gt;
              &lt;label for="last_name"&gt;Last name:&lt;/label&gt;
              &lt;input type="text" name="last_name" class="form-control" t-att-value="last_name" /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
            &lt;div class="col-md-6"&gt;
              &lt;div class="panel panel-default"&gt;
                &lt;div class="panel-heading"&gt;Location information&lt;/div&gt;
                &lt;div class="panel-body"&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-md-12 form-group"&gt;
                      &lt;label class="control-label" for="country_id"&gt;Country:&lt;/label&gt;
                      &lt;select name="country_id" class="form-control"&gt;
                        &lt;option value=""&gt; -- Select country -- &lt;/option&gt;
                        &lt;t t-foreach="countries" t-as="country"&gt;
                          &lt;option t-att-value="country.id"&gt;
                            &lt;t t-esc="country.name" /&gt;
                          &lt;/option&gt;
                        &lt;/t&gt;
                      &lt;/select&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-md-12 form-group"&gt;
                      &lt;label for="company"&gt;Company:&lt;/label&gt;
                      &lt;input type="text" name="company" class="form-control" t-att-value="company" /&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-md-12 form-group"&gt;
                      &lt;label class="control-label" for="sector"&gt;Sector:&lt;/label&gt;
                      &lt;select name="sector" class="form-control"&gt;
                        &lt;option value=""&gt; -- Select sector -- &lt;/option&gt;
                        &lt;option value="1"&gt;Public&lt;/option&gt;
                        &lt;option value="2"&gt;Private&lt;/option&gt;
                        &lt;option value="3"&gt;ONG&lt;/option&gt;
                        &lt;option value="4"&gt;International Organization&lt;/option&gt;
                        &lt;option value="5"&gt;Financial&lt;/option&gt;
                        &lt;option value="6"&gt;Other&lt;/option&gt;
                      &lt;/select&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-md-12 form-group"&gt;
                      &lt;label class="control-label" for="language"&gt;Language:&lt;/label&gt;
                      &lt;select name="sector" class="form-control"&gt;
                        &lt;option value=""&gt; -- Select language -- &lt;/option&gt;
                        &lt;option value="1"&gt;Spanish&lt;/option&gt;
                        &lt;option value="2"&gt;English&lt;/option&gt;
                      &lt;/select&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="col-md-6"&gt;
              &lt;div class="panel panel-default"&gt;
                &lt;div class="panel-heading"&gt;Contact information&lt;/div&gt;
                &lt;div class="panel-body"&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-md-12 form-group"&gt;
                      &lt;label class="control-label" for="email"&gt;Email:&lt;/label&gt;
                      &lt;input type="email" name="email" class="form-control" /&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-md-12 form-group"&gt;
                      &lt;label class="control-label" for="phone"&gt;Phone number:&lt;/label&gt;
                      &lt;input type="tel" name="phone" class="form-control" /&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-md-12 form-group"&gt;
                      &lt;label class="control-label" for="contact_preference"&gt;Contact preference:&lt;/label&gt;
                      &lt;select name="contact_preference" class="form-control"&gt;
                        &lt;option value=""&gt; -- Select preference -- &lt;/option&gt;
                        &lt;option value="1"&gt;Telephone&lt;/option&gt;
                        &lt;option value="2"&gt;Email&lt;/option&gt;
                        &lt;option value="3"&gt;Text message (SMS)&lt;/option&gt;
                        &lt;option value="2"&gt;All of the above&lt;/option&gt;
                        &lt;option value="2"&gt;Dont contact me&lt;/option&gt;
                      &lt;/select&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
            &lt;div class="col-md-12"&gt;
              &lt;ul class="nav nav-tabs"&gt;
                &lt;li class="active"&gt;&lt;a href="#products-interest" data-toggle="tab"&gt;Products of interest&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href="#areas-interest" data-toggle="tab"&gt;Areas of interest&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href="#topics-interest" data-toggle="tab"&gt;Topics of interest&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
              &lt;div class="tab-content"&gt;
                &lt;div id="products-interest" class="tab-pane fade in active"&gt;
                  &lt;h3&gt;Products of interest&lt;/h3&gt;
                  &lt;select name="products_interest" multiple="multiple" class="form-control"&gt;
                    &lt;t t-foreach="products_interest" t-as="product"&gt;
                      &lt;option t-att-value="product.id"&gt;
                        &lt;t t-esc="product.name" /&gt;
                      &lt;/option&gt;
                    &lt;/t&gt;
                  &lt;/select&gt;
                &lt;/div&gt;
                &lt;div id="areas-interest" class="tab-pane fade"&gt;
                  &lt;h3&gt;Areas of interest&lt;/h3&gt;
                  &lt;select name="areas_interest" multiple="multiple" class="form-control"&gt;
                    &lt;t t-foreach="areas_interest" t-as="area"&gt;
                      &lt;option t-att-value="area.id"&gt;
                        &lt;t t-esc="area.name" /&gt;
                      &lt;/option&gt;
                    &lt;/t&gt;
                  &lt;/select&gt;
                &lt;/div&gt;
                &lt;div id="topics-interest" class="tab-pane fade"&gt;
                  &lt;h3&gt;Topics of interest&lt;/h3&gt;
                  &lt;select name="topics_interest" multiple="multiple" class="form-control"&gt;
                    &lt;t t-foreach="topics_interest" t-as="topic"&gt;
                      &lt;option t-att-value="topic.id"&gt;
                        &lt;t t-esc="topic.name" /&gt;
                      &lt;/option&gt;
                    &lt;/t&gt;
                  &lt;/select&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
            &lt;div class="col-md-12"&gt;
              &lt;button type="submit" class="btn btn-default btn-primary"&gt;
                Register &lt;span class="fa fa-long-arrow-right" /&gt;
              &lt;/button&gt;
            &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    &lt;/form&gt;
  &lt;/t&gt;
  </code></pre>
  
  <p></p>
  
  <p>I will really appreciate any help.</p>