Hi everyone! I’m trying to customize my order ID with a prefix and i can’t find the answer!
Here’s my example. My order ID auto incremented from 1 with no max_length, and i want the prefix for example to be AW so the final order id will be AW1, AW2, etc…
cmd_id = models.AutoField(primary_key=True, verbose_name='Numéro de commande', unique=True)
Don’t. At least don’t try to do this directly with auto-increment fields.
Keep the pk as an integer and append the prefix in cases where you need it to be displayed.
You can create a property on the model to concatenate the prefix to it anywhere it’s needed.
Or, create a Database generated model field to create a field with the prefix concatenated to the pk if you really need that string in the database.
If desired, keep the prefix as a field in the database to make it easier to change it when necessary.