syrusakbary/Flask-SuperAdmin

Field name override

mjanv opened this issue · 1 comments

mjanv commented

Hello,

For the purpose of my website, I use Flask-SuperAdmin. I found there is a feature missing (if i'm correct, but i didn't find it after reviewing the code...), so I implemented it. I think it's useful to be able to change the field names which appears in the header of the list.html and are often not good enough for a proper administration section display (not the good language, too obscur,...). Have a way to be able to change it will be great.

The only change I made are these three lines in flask_superadmin/model/base.py

83    field_name_dict = {}
    [...]
206    def field_name(self, field):
207        return prettify(self.field_name_dict.get(label,label))

Therefore, we just have to define a field_name_dict into a Model View to do the job. For example,

class UserModel(BaseModel):
    list_display = ('username','email',)
    field_name_dict =  { 'username' : 'Pseudo' , 'email' : 'Courriel' }

capture d ecran 2015-08-25 a 16 59 59

If it seems to be a good feature to add, I can propose a merge request.

Good idea +1