wogsland
wogsland

Reputation: 9508

Removing help_text in Django admin from read only fields

So I have an admin like so:

class BlahAdmin(admin.ModelAdmin):
    fields = (
        'name', 'status', 'created_date'
    )
    readonly_fields = (
        'created_date'
    )

And each of these fields has an annoying help_text that I don't want to display. Now I can get rid of two of them fine with

class BlahForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(BlahForm, self).__init__(*args, **kwargs)
        for fieldname in ['name', 'status']:
            self.fields[fieldname].help_text = None

and adding the line

form = BlahForm

to BlahAdmin, but if I tried to add created_date to the field names looped over I get a 500 error. What am I missing here?

Upvotes: 1

Views: 515

Answers (1)

Cyrlop
Cyrlop

Reputation: 1984

Where did you define the help text, in the model? Can you just remove it? If not you can do this:

class BlahAdminForm(forms.ModelForm):
    class Meta:
        model = Blah
        fields = '__all__'
        help_texts = {"created_date": None}

and still add this to your BlahAdmin:

form = BlahAdminForm

Upvotes: 1

Related Questions