title: Django: How to make a form with custom templating?
body: <p>I have a model:</p>
  
  <pre><code>class Setting(models.Model):
  
      class Meta:
          abstract = True
  
      name = models.CharField(max_length=120, primary_key=True)
      description = models.CharField(max_length=300, blank=True)
  
  class IntegerSetting(Setting):
      value = models.IntegerField()
  </code></pre>
  
  <p>I would like to create a form that looks something like:</p>
  
  <pre><code>&lt;form method="POST" action=""&gt;
       {% for model in models %}
       &lt;label&gt;{{model.name}}&lt;/label&gt; &lt;input value='{{model.value}}' /&gt;
       &lt;p&gt;{{model.description}}&lt;/p&gt;
       {% endfor %}
  &lt;/form&gt;
  </code></pre>
  
  <p>I'm not quite sure how to go about doing this. Perhaps I need to use a formset?</p>
  
  <pre><code>from django.forms.models import modelformset_factory
  from apps.about.models import Setting, IntegerSetting
  
  def site_settings(request):
      formset = modelformset_factory(IntegerSetting)()
  
      return render_to_response("about/admin/site-settings.html", {'formset': formset}, RequestContext(request, {}))
  </code></pre>
  
  <p>Then in the template, I'd want to render the form differently than default. I'm not quite sure how to go about accessing the model properties, however. Is this the right approach, or is there another way I should be going about doing this?</p>
  
  <p><strong>Update</strong>: This is what I'm currently doing. It renders exactly as I'd like it to, aside from the styling. However, I feel that it's deeply hacky:</p>
  
  <pre><code>class SettingsForm(ModelForm):
      class Meta:
          model = IntegerSetting
  
      def as_table(self):
          bound_field = BoundField(self, self.fields['value'], 'value')
          return mark_safe("&lt;tr&gt;&lt;td&gt;&lt;label&gt;%s&lt;/label&gt;&lt;/td&gt;&lt;td&gt;%s\n&lt;p class='help'&gt;%s&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;" % (self.instance.name,
                                                                         self.instance.description, 
                                                                         bound_field.__unicode__())) 
  
  def edit_settings(request):
      forms = [SettingsForm(instance=intSetting) for intSetting in IntegerSetting.objects.all()]
  
      return render_to_response("admin/edit-settings.html", {'forms': forms}, RequestContext(request, {}))
  </code></pre>
  
  <p><strong>edit-settings.html</strong>:</p>
  
  <pre><code>{% extends "admin/base_site.html" %}
  {% block title %}System Settings{% endblock %}
  
  {% block content %}
      &lt;form method="post" action=""&gt;
          &lt;table&gt;
          {% for form in forms %}
          {{form}}
          {% endfor %}
          &lt;/table&gt;
      &lt;/form&gt;
  {% endblock %}
  </code></pre>
  
  <p>Is there a better approach to this?</p>
  
  <p>Also, I'm not sure if I'll encounter problems when the form is submitted or not.</p>