title: Accessing Many to Many "through" relation fields in Formsets
body: <p>My Models:</p>
  
  <pre><code>class End_User(models.Model):
      location = models.ForeignKey(Location) 
      first_name = models.CharField(max_length=70, blank=True, null=True)
      email_address = models.CharField(max_length=70, blank=True, null=True)
  
  class Phone_Client(models.Model):
      end_user = models.ManyToManyField(End_User)
  ...
      extensions = models.CharField(max_length=20)
  
  class Line(models.Model):
      phone_client = models.ManyToManyField(Phone_Client, through='Phone_Line' )
      ....
      voicemail = models.BooleanField(default=False)  
  
  class Phone_Line(models.Model):
      phone_client = models.ForeignKey(Phone_Client)
      line = models.ForeignKey(Line)
      line_index = models.IntegerField()
  </code></pre>
  
  <p>So basically One end user can have many phones, a phone can have many Lines, related through Phone_line.</p>
  
  <p>My page need to have all these objects editable and new instances created runtime for Phone_Clients and Line all in the same page. Currently I am creating a simple End_User model form and modelformset_factory objects for Phone_Client and Lines. Since a phone can have many lines, each phone form in the phone_formset can have a line formset object. I am currently doing something like this </p>
  
  <pre><code>end_user = End_User.objects.get(pk=user_id)
  user_form = End_UserForm(instance=end_user)
  
  Phone_ClientFormSet = modelformset_factory(Phone_Client,form=PartialPhone_ClientForm,  extra=0, can_delete=True)
  
  phone_clients_formset = Phone_ClientFormSet(queryset=end_user.phone_client_set.all(), prefix='phone_client')
  
  all_lines = modelformset_factory(Line, form=PartialLineForm, extra=0, can_delete=True)
  
  phone_clients = end_user.phone_client_set.all()
  
  client_lines_formsets = {}
  for phone in phone_clients:
      client_lines_formsets[phone.id] = all_lines(queryset=phone.line_set.all(), prefix='phone_client_'+str(phone.id))
  </code></pre>
  
  <p>I am using this list to display lines belonging to a phone_client in the template using formsets.</p>
  
  <p>I have the following question, on the models</p>
  
  <ol>
  <li><p>Can I use inline_formset factory to handle many to many relation containing a through class? if so how do I do that for the Phone_Client, Line and Phone_Line through relation?</p></li>
  <li><p>I need to display the line_index for a given phone, line combination, how do I do that in template?  I have looked at<br>
  <a href="https://stackoverflow.com/questions/3368442/how-do-i-access-the-properties-of-a-many-to-many-through-table-from-a-django-t">How do I access the properties of a many-to-many &quot;through&quot; table from a django template?</a>
  I do not want to only display, but bind the value to the phone, line combination if possible in the line or phone formset, such that if user changes the index, I can save that in the data base while posting the formset data.</p></li>
  </ol>
  
  <p>I am new to django so any help is really appreciated.
  Thanks!!</p>