如何在django后端保存拖放?

时间:2022-06-26 07:21:50

I'm trying to create a drag and drop function in my project that when ever i drop an item it automatically saves in the backend side.

我正在尝试在我的项目中创建一个拖放功能,当我丢弃一个项目时它会自动保存在后端。

    <script style="text/javascript">
$(function() {
    $( "#roles li" ).draggable({
        appendTo: "body",
        helper: "clone",
        });
    $( "#item-roles li" ).droppable({
        activeClass: "ui-state-default",
        hoverClass: "ui-state-hover",
        accept: ":not(.ui-sortable-helper)",
        drop: function( event, ui ) {
            alert('you drop this')
            $( "<li></li>" ).text( ui.draggable.text() ).appendTo( this );
        }
    })
});

In my Html code goes here.

我的Html代码就在这里。

    <div id="item-roles">
    <h3>Role in {{item.name|title}} Item</h3>
        <ul>
        <h3>Drag role here!</h3>
        {% for item_role in item_roles %}
            <li class="placeholder" style="list-style-type: none;">
                {{item_role.show_role}} <a href="#">Remove</a>
            </li>
        {% empty%}
            <li>No items found</li>
        {% endfor %}
        </ul>            
</div>

<div id="roles">
    <h3>Roles in this Show</h3>
        <ul>
            {% for role in roles %}
                <li>
                <a class="role-detail">{{ role.role_name }}</a>
                </li>

            {% empty %}
                <p>No show roles </p>
            {% endfor %}
        </ul>

1 个解决方案

#1


1  

You can use dajaxice (and dajax) for calling your django functions "from" javascript. Now you need to write down your python code which is missing from your question...

你可以使用dajaxice(和dajax)从“javascript”调用你的django函数。现在你需要记下你的问题中缺少的python代码......

#1


1  

You can use dajaxice (and dajax) for calling your django functions "from" javascript. Now you need to write down your python code which is missing from your question...

你可以使用dajaxice(和dajax)从“javascript”调用你的django函数。现在你需要记下你的问题中缺少的python代码......