django - how to store registration value in to database? -


i trying store registration value in database getting error.

the code 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">&nbsp;&nbsp;&nbsp;  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">&nbsp;&nbsp;&nbsp;  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">&nbsp;&nbsp;&nbsp;<input type="button" id="cancel_id" value="cancel">   </form>  </body>  </html> 

error:

 invalid literal int() base 10: ''  error on:          queryset1.save() 

so solve problem can can store registration values databese?

this string:

  plate = request.post.get("plate_id", ' ') 

convert integer before saving it. db expects integer.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -