class MyModelForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(MyModelForm, self).__init__(*args, **kwargs) self.initial['some_field'] = some_encoding_method(self.instance.some_field) class MyModelAdmin(admin.ModelAdmin): form = MyModelForm ...
Where, some_encoding_method will be what you configured to define spacing / indentation or some other third-party functions that you borrow. However, if you write your own method, it would be better to put it in the model itself, and then call it through an instance:
class MyModel(models.Model): ... def encode_some_field(self):
Then:
self.instance.encode_some_field()
source share