title: Dynamic Table with django form
body: <p>So I've read the docs and looked at a couple of answer but I think I'm confusing myself here. </p>
  
  <p>I'm trying to build a table that can have dynamically added rows to it. My table row is constructed from my form called <code>ModbusRegistersForm</code>. The difficulty I'm having here is understanding how this will work with my form since every time a row is added, it's basically another <code>ModbusRegistersForm</code> being added(via jquery). What would be an acceptable way of adding these dynamically added fields to my form? Since each row is pretty much a duplicate of <code>ModbusRegistersForm</code>, should they all be added to a list inside <code>ModbusRegistersForm</code>? or is there a specific way to go about this? I'm currently looking at formsets but from the docs it seems (to me at least) like you'd have to pre-define the amount of <code>extra</code> forms you want so it won't work since it's dynamic.</p>
  
  <pre><code>class ModbusRegistersForm(forms.Form):
      OPTIONS = (('1', '(01) Discrete Output Coils'),
                 ('2', '(02) Discrete Input Contacts'),
                 ('3', '(03) Analog Output Registers'),
                 ('4', '(04) Analog Input Registers')
                 )
  
      starting_address = forms.IntegerField(max_value=99999,
                                            widget=forms.TextInput(attrs={
                                                      'placeholder': 'Starting address',
                                                      'class': 'form-control'
                                                }))
      ending_address = forms.IntegerField(max_value=99999,
                                            widget=forms.TextInput(attrs={
                                                      'placeholder': 'Ending address',
                                                      'class': 'form-control'
                                                }))
      register_type = forms.ChoiceField(widget=forms.Select(attrs={
                                                      'class': 'form-control',
                                                      'id': 'register-type'
                                                }), 
                                                 choices=OPTIONS
                                               )
      offset = forms.IntegerField(max_value=9999,
                                  required=False,
                                  widget=forms.TextInput(attrs={
                                          'class': 'form-control',
                                          'placeholder': 'Address offset'
                                      }))
  
  class CreateModbusForm(forms.Form):
      port = forms.IntegerField(label="TCP/IP Port:",
                                max_value=65535,
                                validators = [[RegexValidator(regex='\d{1,5}', message='Not a valid port', code='Invalid port')]],
                                widget=forms.TextInput(attrs={
                                          'placeholder': 'Port',
                                          'class': 'form-control',
                                          'id': 'port',
                                    }))
      slave_id = forms.IntegerField(label="Slave ID:",
                                max_value=247,
                                widget=forms.TextInput(attrs={
                                          'placeholder': 'Slave id',
                                          'class': 'form-control',
                                          'id': 'slave-id',
                                    }))
      ip_address = forms.CharField(label="IP Address",
                           max_length=16,
                           widget=forms.TextInput(attrs={
                                  'placeholder': 'Modbus IP address',
                                  'class': 'form-control',
                                  'id': 'ip-address',
                              }))
  
      device_name = forms.CharField(label="Device Name:", 
                                    max_length=50, 
                                    widget=forms.TextInput(attrs={
                                        'placeholder': 'Modbus device name', 
                                        'class': 'form-control', 
                                        'id': 'device-name'
                                        }))
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>    modbus_device = CreateModbusForm()
      registers = ModbusRegistersForm()
  
      return render(
          request,
          'app/create_modbus.html',
          context_instance = RequestContext(request,
          {
              'title':'Create Modbus Device',
              'tag': 'create_modbus',
              'modbus_device': modbus_device,
              'registers': registers
          })
      )
  </code></pre>
  
  <p>html</p>
  
  <pre><code>                                 &lt;tbody&gt;
                                      &lt;tr id='addr_0'&gt;
                                          &lt;td&gt;
                                          1
                                          &lt;/td&gt;
                                          &lt;td&gt;
                                              {{ registers.starting_address }}
                                          &lt;/td&gt;
                                          &lt;td&gt;
                                              {{ registers.ending_address }}
                                          &lt;/td&gt;
                                          &lt;td&gt;
                                              {{ registers.register_type }}
                                          &lt;/td&gt;
                                          &lt;td&gt;
                                              {{ registers.offset }}
                                          &lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr id='addr_1'&gt;&lt;/tr&gt;
                                  &lt;/tbody&gt;
  </code></pre>