如何检索以表格形式动态显示的列

时间:2019-04-29 08:42:13

标签: post datatable django-forms django-templates

我想检索动态创建的数据表的每一行。我用post方法创建了一个表单来获取这些行,但是我不知道如何在视图函数中编写将它们存储在Panda DataFrame中的内容。

<form action="{%url 'livedb_model:validation' property.id roomtype.id %}?normal_price={{normal_price}}&week_day_multi={{week_day_multi}}&week_end_multi={{week_end_multi}}&max_discount={{max_discount}}&max_markup={{max_markup}}&coccCategory={{coccCategory}}&agressiveness={{agressiveness}}" method="post">
        {% csrf_token %}
        <input class='btn btn-primary btn-large btn-block align-self-center'type='submit' value='submit'>
        <div id="datatable" class="table-editable align-self-stretch">
        <table class="table table-bordered table-responsive-md table-striped text-center">
            <tr>
            <th class="text-center">Date</th>
            <th class="text-center">Availability</th>
            <th class="text-center">Current Price</th>
            <th class="text-center">Current Occupancy</th>
            <th class="text-center">Advised Price</th>
            </tr>
                {% for day in invdf.itertuples %}
                <tr>
                    {% if day.availability.room %}
                        <td class="pt-3-half" id='date'>{{day.date|date:'M d,Y'}}</td>
                        <td class="pt-3-half">{{day.allotment}}</td>
                        <td class="pt-3-half">{{day.price|floatformat:2}}</td>
                        <td class="pt-3-half">{{day.occupancy|floatformat:2}}</td>
                        <td class="pt-3-half" id='price_advised' contenteditable="true">{{day.price_advised|floatformat:2}}</td>
                    {% else %}
                        <td class="pt-3-half" id='date'>{{day.date|date:'M d,Y'}}</td>
                        <td class="pt-3-half">{{day.allotment}}</td>
                        <td class="pt-3-half">{{day.price|floatformat:2}}</td>
                        <td class="pt-3-half">{{day.occupancy|floatformat:2}}</td>
                        <td class="pt-3-half" id='price_advised' contenteditable="true">{{day.price_advised|floatformat:2}}</td>
                    {% endif %}
                </tr>
                {% endfor%}
        </div>
    </form>

例如,我想在自己的观点中写点东西:

def validation(request,id,rt_id):
    if request.method=='POST':
        price_advised=request.POST.get(ADVISED PRICE COLUMN)

您能帮我吗? 谢谢

1 个答案:

答案 0 :(得分:0)

您可以在提交表单之前使用javascript add参数