To solve the problem of "concatenating" the numbers just use math, if you are using the year with 4 digits as a base, simply multiply the year by 10,000, ie you will add 4 zeros to the right of the year. After that, just add the next number.
2018 * 10000 + 1 # 20180001
2018 * 10000 + 2 # 20180002
2018 * 10000 + 3 # 20180003
# ...
Example of a generator that does what you need:
def numero_solicitacao(ano = None, numero_inicial = 1):
ano_atual = ano or date.today().year
numero = numero_inicial
while numero <= 9999:
yield ano_atual * 10000 + numero
numero += 1
gen_numero = numero_solicitacao()
print(next(gen_numero)) # 20180001
print(next(gen_numero)) # 20180002
print(next(gen_numero)) # 20180003
gen_numero = numero_solicitacao(2011, 500)
print(next(gen_numero)) # 20110500
print(next(gen_numero)) # 20110501
print(next(gen_numero)) # 20110502
Note that I set the parameters ano
and numero_inicial
so that you can start at the number you need, this way you can get the last record that you have in the database and use the generator to follow it number onwards.
Repl.it with the code working.