title: How to save User objects in many to many field?
body: <p>I'd like to save two user objects in a <code>ManyToManyField</code> after a form <code>POST</code>, like so :</p>
  <pre><code>ManytoManyField: [&lt;User: user1&gt;, &lt;User: user2&gt;]
  </code></pre>
  <p>here is the error I get when I try to save the m2m field :</p>
  <blockquote>
  <p>ValueError: &quot;...&quot; needs to have a value for field &quot;message&quot; before this many-to-many relationship can be used.</p>
  </blockquote>
  <p>Here is what my code looks like, templates/<strong>page.html</strong></p>
  <pre><code>&lt;form method=&quot;POST&quot; action=&quot;...to my view...&quot;&gt;
      {% csrf_token %}
      &lt;input name='message'&gt;
      &lt;button type=&quot;submit&quot;&gt;Send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>if request.method == 'POST':
      user1 = ...&lt;User: user1&gt;...
      user2 = ...&lt;User: user2&gt;...
      two_users = user1, user2
  
      form = MessageForm(request.POST)
      if form.is_valid():
          save_it = form.save(commit=False)
          for u in two_users
              save_it.users.add(u)
          save_it.save()
          return redirect('/')
      ...
  
  return render(request, &quot;room.html&quot;, {...})
  </code></pre>
  <p><strong>models.py :</strong></p>
  <pre><code>class Message(models.Model):
      users = models.ManyToManyField(User)
      message = models.CharField(...)
      ...
  </code></pre>
  <p>This code is an example of what I'm trying to do, this is what it should look like in the admin page after being saved :</p>
  <p><a href="https://i.stack.imgur.com/fVgdT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fVgdT.jpg" alt="enter image description here" /></a></p>
  <p>How can I achieve this ?</p>