5

I am trying to add multiple inline form items to a page using Djangos ModelForms. I need Select boxes bound to database models. The forms are formatted and placed in a tabular format so I need to display only the ModelForm without ANY surrounding HTML.

class LeagueForm(ModelForm):
league = forms.ModelChoiceField(queryset=League.objects.all(), empty_label='Manual Team Entry:', required=False)

class Meta:
    model = League
    exclude = ['league_name']

Template:

{% if selected_sport == 1 %}        
<td>{{ nhl_form.as_p }}</td>
{% else %}

The problem is I dont want the paragraph tags, nor tables tags or anything at all. I need to have the form nicely sit where I place it without garbling up the surrounding html.

Can anyone please point me in the right direction? Thanks

2 Answers 2

16

Just refer to each field separately.

{{ nhl_form.league }}

will only show the league field, with no surrounding cruft.

Sign up to request clarification or add additional context in comments.

3 Comments

And how can I add extra custom CSS class names to each field (for processing with CSS/jQuery later on)?
@viet, that documentation was very helpful as I did not want to refer to each field separately.
0

see also http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.