من الان که اکشن این دستم نیست ولی یچیزی شبیه به این :
def search_tahvil_sandogh(request) :
data = {}
user = ''
date = ''
if 'date' in request.POST :
date = request.POST['date']
if 'user' in request.POST :
user = request.POST['user']
sandogh = ''
if user != '' :
try :
user1 = User.objects.get(username = user )
except :
data['sandogh'] = ''
data['remain'] = ''
data['error'] = 'نام کار بری فوق معتبر نمی باشد'
json1 = simplejson.dumps(data)
return HttpResponse(json1, mimetype='application/json')
sandogh = tahvil_sandogh.objects.filter(user = user1 )
if date != '' :
if sandogh != '' :
sandogh = sandogh.filter( date = date )
else :
sandogh = tahvil_sandogh.objects.filter(date = date )
print sandogh
if sandogh != '' and len(sandogh) > 0 :
data['error'] = ''
data['search'] = render_to_string('tahvil_sandogh_search.html', {"tahvil" : sandogh }, context_instance=RequestContext(request))
json1 = simplejson.dumps(data)
return HttpResponse(json1, mimetype='application/json')
else :
data['error'] = 'موردی یافت نشد'
data['search'] = ''
json1 = simplejson.dumps(data)
return HttpResponse(json1, mimetype='application/json')
اسکریپتش هم میشه :
$('#search_kol').click(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "/search_tahvil_sandogh/", //**Your full URL goes here**
data: $('#Form_tahvil_sandogh').serialize(),
dataType: 'json',
success: function(data, textStatus, jqXHR){
$("#m450").html(data.search);
$("#error").html(data.error);
},
error: function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
}
});
});