def add_car(request):
""" Lets user add car card """
if request.POST:
data = request.POST
car_dict = dict()
car_dict['model'] = data.get('model')
car_dict['brand'] = data.get('brand')
car_dict['year'] = data.get('year')
car_dict['vin'] = data.get('vin')
json_data = json.dumps(car_dict)
MyCar.objects.create(car=json_data)
return render(request, 'car_adding_form.html', locals())
$(document).ready(function(){
$("#add_car").click(function(e){
e.preventDefault();
var extraForm = document.createElement('DIV');
$(extraForm).attr("data-is-sent", 0);
...
...
...
$.ajax({
type: "POST",
data: data,
cache: true,
});
$("[data-is-sent='0']").attr("data-is-sent", 1);
});
});
{"vin": null, "brand": null, "year": null, "model": null}