Write not fully displayed Django field

41 Views Asked by At

I need to write a Django custom field where the stored value is not fully displayed. For example if the stored value is "079684" I need it to be displayed as "---84". Is it possible to do so ? If yes how should I implement my custom field ?

2

There are 2 best solutions below

0
Uroš Trstenjak On

You could store your value as a string in your model and than use slice in template to show only last two character.

{{ value|slice:"-2:" }}
1
Akamee On

I have solved this by overriding from_db_value() of the custom field method.