Reputation: 517
i am trying to store registration value in to database but i am getting error.
the code for this is as below.
views.py
def car_vw(request):
plate = request.POST.get("plate_id", ' ')
brand = request.POST.get("brand_id", ' ')
model = request.POST.get("model_id", ' ')
price = request.POST.get("price_id", ' ')
condition = request.POST.getlist("select_id[]", ' ')
queryset1 = car(plate_no=plate, brand=brand, model=model, daily_price=price, Condition=condition,)
queryset1.save()
data = {
'queryset1': queryset1,
}
return render(request, 'car_registration.html', data)
Models.py
class car(models.Model):
car_id = models.IntegerField(max_length=400, primary_key=True)
plate_no = models.IntegerField(max_length=400)
brand = models.CharField(max_length=400)
model = models.CharField(max_length=400)
Condition = models.CharField(max_length=400)
daily_price = models.IntegerField()
def __str__(self):
return ' '.join([
self. ordering,
])
.html
<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
<title></title>
<link href="{{ static }}css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<form action="/car/" id="form_id" method="post">
{% csrf_token %}
<h3>car Registration</h3>
plate no:<input type="text" id="plate_id" name="plate_id">
Brand:<input type="text" id="brand_id" name="brand_id"><br>
Model:<input type="text" name="model_id">
Daily Price:<input type="text" id="price_id">
Condition:<select name="select_id[]"><option value="Good">Good</option>
<option value="middle">Middle</option>
<option value="bad">BMW</option></select>
<br>
<input type="submit" id="sub_id"> <input type="button" id="cancel_id" VALUE="Cancel">
</form>
</body>
</html>
Error:
invalid literal for int() with base 10: ''
error on:
queryset1.save()
So for solve this problem what can i do so i can easily store the registration values to databese?
Upvotes: 0
Views: 56
Reputation: 2166
This is a string:
plate = request.POST.get("plate_id", ' ')
Convert it to an integer before saving it. Your DB expects an integer.
Upvotes: 1