Stacked/Grouped Forms 2 - easy rendering forms

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django.forms.forms import BoundField

class FieldStack(object):
    """ EXAMPLE:

    class MyForm(forms.Form):
        first_name = forms.CharField()
        last_name = forms.CharField()
        website = forms.CharField()
        twitter = forms.CharField()
        facebook = forms.CharField()

        personal_info = FieldStack('first_name', 'last_name')
        contact_info = FieldStack('website', 'twitter', 'facebook')
    
    <ul>{% for field in form.personal_info %}
        <li>{{field.name}}: {{ field }}{{field.errors}}</li>
    {% endfor %}</ul>
    
    <table>{% for field in form.contact_info %}
        <tr><td>{{field.name}}</td><td>{{ field }}</td><td>{{field.errors}}</td></tr>
    {% endfor %}</table>
    """

    def __init__(self, *args):
        self.fields = args
        
    def __get__(self, form, objtype=None):
        for field in self.fields:
            yield BoundField(form, form.fields[field], field)

More like this

  1. FieldStack - easy form template rendering by diverman 3 years, 11 months ago
  2. Stacked/Grouped Forms by flashingpumpkin 4 years, 5 months ago
  3. Form field sets by gonz 4 years, 3 months ago
  4. FieldsetForm by Ciantic 7 years ago
  5. Easy Form Structuring by jug 4 years, 8 months ago

Comments

(Forgotten your password?)