list_editable and widgets

后端 未结 2 1561
误落风尘
误落风尘 2021-02-03 10:28

When using list_editable in ModelAdmin, is there any way to change the widget used for the editable fields? I can\'t find anything in the documentation. Seems like

2条回答
  •  时光取名叫无心
    2021-02-03 11:09

    If you want to change widget only (tested on django 1.5) you won't need to set labels ect. just use this syntax:

    from django import forms
    
    class OfferForm(forms.ModelForm):
        class Meta:
            model = Offer
            widgets = {
                'description' : forms.Textarea(
                    attrs={
                        'cols': '20',
                    }
                )
            }
    

    Where widgets dict is dict whose keys are names of fields and values represents widgets you want to override.

    As documentation states for django 1.5+ its also possible to just:

    class OfferAdmin(admin.ModelAdmin):
        def get_changelist_form(self, request, **kwargs):
            return OfferForm
    

    Without any super() and kwargs juggling.

提交回复
热议问题