codyc4321
codyc4321

Reputation: 9682

breaking form fields up separately django

I have a form that makes 14 fields, an opening and closing field for each day. I am having problems displaying each on its own, so I can include the days in between. My form is making fields such as 'open_time_1', 'close_time_1' up to 7. I currently have

{{ schedule_form.fields.close_time_1 }}

in my template, which was promising, but is causing enter image description here

How can I get the nitty gritty of django form fields in general to display manually like that? Thank you

Upvotes: 0

Views: 286

Answers (1)

Wtower
Wtower

Reputation: 19912

I would try {{ schedule_form.close_time_1 }}.

This renders the field without any label markup. This is some code I use to render a field with bootstrap:

<div class="form-group">
    <span class="field-label">{{ field.label_tag }}</span>
    {% if field.field.required %}<span class="required">*</span>{% endif %}
    <span class="field-item">{{ field }}</span>
    <div class="field-help">{{ field.help_text }}</div>
    {% if field.errors %}<div class="alert alert-warning" role="alert">{{ field.errors }}</div>{% endif %}
</div>

Where field is eg. schedule_form.close_time_1.

More on the topic in Django docs: Working with forms.

Upvotes: 1

Related Questions