Django:ajax和请求

I don`t speak english well? but i have problem in Django. I have models:

class Model1(models.Model):
    model2 = models.ManyToManyField(Model2)
    #...
class Model2(models.Model):
    model3 = models.ForeignKey(Model3)
    #...
class Model3(models.Model):
    custom = models.CharField()

have view

def simple(request, simple_id):
    if request.method == 'POST':
        if request.is_ajax():
            if 'delete' in request.POST:
                id3 = request.POST.get('delete', '')
                Model1.objects.get(id = simple_id).model2.filter(model3__id = id3).delete()

That is, when submitting a form with name = "delete" Ajax have removed all the objects belonging to Model2 with the same value of the field "model3" Here's a piece of template:

<form action="" method="post" id="simple">{% csrf_token %}
<input type="submit" name="delete" id="simple_delete" value="">
</form>

the value passed from js:

$('.deletebutton').click(function(){
    id = $(this).attr('data-id');
    $('#simple_delete').attr('value', id);
    $('#simple').ajaxForm();
    $('#simple_delete').click();
});

Well, respectively plugin jquery.form.js also connected

The problem is this - if submission without ajax all is normal, it works ... and if with Ajax is an error such as incorrect int value ... How to make it work via Ajax?

try this

$('.deletebutton').click(function(){
     id = $(this).attr('data-id');
     $.ajax(function(){
         type:"POST",
         url :"/your_url/",
         data:{
              'id'=id,
         }
    }).done(function(result){
         alert('your json object result render by view :'+result)
    })

i think it work, and i didnt get wat you are doing in i.e $('#simple_delete').click(); can you please describe about that

in view

obj = Model1.objects.get(id = simple_id)
model2.objects.filter(model3__id = id3).delete()

i just split single line query into two lines and if not working use .select_related()