1👍
Without knowing more about your code I will address a couple of issues related with these lines:
#...
new_car = int(self.data.get(f'cardefination_set-{i}-new_car', []))
old_car =int(self.data.get(f'cardefination_set-{i}-old_car', []))
#...
The issue is the same in both lines. You are casting
(explicit type conversion) a value to int
using int(value)
. This means that the value must be "convertible" to int
. In your case you are getting a value from self.data
, that I am going to assume it is a dictionary. If the obtained value can’t be converted to int
you will get that error.
Moreover, I see you are using the default value parameter on the dict.get(key, value)
function.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this method never raises a KeyError.
The default value you are providing is []
which is a list
, i.e. int([])
will throw:
TypeError: int() argument must be a string, a bytes-like object or a real number, not ‘list’
That error is not the error you are mentioning, but just wanted to point that out.
I think your issue is that the value you are getting from the dictionary is an empty string.
Hence your error:
ValueError invalid literal for int() with base 10: ”
Make sure what you are getting from the dict can be converted to int