Horizontal (per-row) forms in a Django formset

前端 未结 2 405
忘掉有多难
忘掉有多难 2020-12-13 20:54

What\'s the Django way of presenting a formset horizontally, i.e. one row per form? The as_table method generates multiple forms vertically (with the labels). I need the fo

2条回答
  •  情书的邮戳
    2020-12-13 21:46

    I suggest using form.as_ul and styling it with your CSS to make it all on one row. You can do that with ul li { display: inline; } or of course, substitute a class or ID if you don't want to affect all ULs in that manner.

    Here's the relevant section of the Django docs: http://docs.djangoproject.com/en/dev/topics/forms/#displaying-a-form-using-a-template

    Edit: To address your need for a table, you'd like want to do something like this... edited some more.

    It's difficult to put all of these forms in a table, and still have valid HTML. A form element can surround a table, or be inside a ... though this will likely still work.

    
      
       {% for field in form %}
         {{ field.label }}
       {% endfor %}
      
    
    
    
     
      
    {% for field in form %}
    {{ field.label }}
    {{ field }}
    {% endfor %}

提交回复
热议问题