Django - How to delete a object directly from a button in a table

后端 未结 2 1380
迷失自我
迷失自我 2021-02-09 21:11

(sorry for my bad english)

I need to delete an object, but directly from a list of the objects that y have in my template.

I have a work orders, that have spare

2条回答
  •  故里飘歌
    2021-02-09 21:53

    here in fa fa-thrash pass the id and the URL as I did it:-

    {% if spare_parts %}
                  
                      {% for part in spare_parts %}
                      
                        {% if part.price %}
                        
                        {% else %}
                        
                        {% endif %}
                        
                      {% endfor %}
                    
    {% trans "Spare Part" %} {% trans "Price" %} {% trans "Delete" %}
    {{ part.spare_part }}$ {{ part.price }}
    {% else %}

    NO HAY REPUESTOS ASENTADOS AÚN

    {% endif %}

    ur url would be sonething like that:

    url(r'^delete/(?P[0-9]+)/$', view.function, name='delete_view'),
    

    in ur view:

    def function(request,part_id =None):
        object = YourModel.objects.get(id=part_id)
        object.delete()
        return render(request,'ur template where you want to redirect')
    

提交回复
热议问题