views:

320

answers:

1

Hi,

I create a form based on a model , like seen below:

class ContactSelectionForm(forms.ModelForm):

    contacts = ManyToManyByLetter(Contact, field_name="first_name")

    class Meta:
        model = ContactSelection
        exclude = ('created_by',)

When I process this view I see at the .html output a field labeled with "Contact". Now I`m wondering whether it is possible to change this output. For example I want to name this field not "Contact" but "Selected Contacts".

This is the form processing part of the .html template:

<form action="{{ request.path }}" method="POST">
        <div> 
            <fieldset class="module aligned"> 
                {% for field in form.visible_fields %}
                    <div class="form-row">
                    {# Include the hidden fields in the form #}
                    {% if forloop.first %}
                        {% for hidden in form.hidden_fields %}
                        {{ hidden }}
                        {% endfor %}
                    {% endif %}

                    {{ field.errors }}
                    {{ field.label_tag }} {{ field }}
                    </div>
                {% endfor %}
                <p><input type="submit" value="Save" /></p>
            </fieldset>
        </div>
    </form>

If somebody is wondering what ManyToManyByLetter(Contact, field_name="first_name") in the form is, check out http://code.google.com/p/django-ajax-filtered-fields/ . A very helpful many2many javascript library.

+2  A: 

Did you try setting the fields label? (the docs)

contacts = ManyToManyByLetter(Contact, field_name="first_name", label="Selected Contacts")
Ofri Raviv
No I didn`t tried it before. But it works. Thank you. I should become more familiar with the docs and not trying to search everything on google.
Tom Tom
You're welcome. Yea. the docs are great. and anyway, its almost always the first result for searches like django+form+label
Ofri Raviv