Django Admin widget 셋팅 주의점

2021. 2. 7. 13:03파이썬/Django

적용안됨 : field.widget.attrs['size'] = 5

적용됨 : field.widget = forms.TextInput(attrs={'size'5})

    
    def formfield_for_dbfield(self, db_field, **kwargs):
        field = super(ImageAdmin, self).formfield_for_dbfield(db_field, **kwargs)
        if db_field.name in ('lang') :
            field.widget = forms.TextInput(attrs={'size': 5})
            #field.widget.attrs['size'] = 5
        return field