mainapp/views.py
def delete_product(request, pk):
    """
    Deletes item from the database.
    :param request: request object.
    :param pk: id of item to be deleted.
    :return: updated list of products.
    """
    if request.is_ajax():
        item = Product.objects.filter(pk=pk).first()
        if item:
            item.delete()
        data = {
            'products_html': render_to_string(
                'mainapp/product_list.html',
                context={'products': Product.objects.all()},
                request=request
            )
        }
        return JsonResponse(data)

    Deletes item from the database.
    :param request: request object.
    :param pk: id of item to be deleted.
    :return: updated list of products.
    
Deletes item from the database.
Deletes item from the database .
def delete_product(request, pk):
    if request.is_ajax():
        item = Product.objects.filter(pk=pk).first()
        if item:
            item.delete()
        data = {
            'products_html': render_to_string(
                'mainapp/product_list.html',
                context={'products': Product.objects.all()},
                request=request
            )
        }
        return JsonResponse(data)
def delete_product ( request , pk ) : if request . is_ajax ( ) : item = Product . objects . filter ( pk = pk ) . first ( ) if item : item . delete ( ) data = { 'products_html' : render_to_string ( 'mainapp/product_list.html' , context = { 'products' : Product . objects . all ( ) } , request = request ) } return JsonResponse ( data )
Deletes item from the database.
Deletes item from the database .
"""
    Deletes item from the database.
    :param request: request object.
    :param pk: id of item to be deleted.
    :return: updated list of products.
    """
updated list of products.
updated list of products .
request
None
pk
id of item to be deleted.
id of item to be deleted .