[Answered ]-Appending a 0 in front of a variable in Python

1👍

You should cast the 0 to unicode or string before concatenating.

fab = "0" + fab

You can not concatenate a unicode variable with an integer, you can also not concatenate strings with integers or floats, so you need to convert one to the correct type.

1👍

It sounds like your logic is wrong somewhere,

You are either trying to force an integer into a CharField or you are trying to force a string into an IntegerField. If its the former you’re always going to struggle with having to cast values to get the correct results and if its the latter the leading 0 is pointless.

You should try to use the correct field type, it will even help with your model’s validation.

👤Sayse

Leave a comment