Mirage
Mirage

Reputation: 31548

How to override the model field in django form

In my Model i have this

description = tinymce_models.HTMLField(help_text='A short descripton')

Now i want to render this field as normal text area not the tinymece field. I can't edit the models file.

Is there any way i can override the same field in my form.

like this

description = forms.widgets.Textarea(attrs={'rows':4, 'cols':40})

I tried this but didn't worked

Upvotes: 1

Views: 191

Answers (1)

Rohan
Rohan

Reputation: 53326

you can specify what widget you want to use in modelforms Meta class. For example:

class MyModelForm(ModelForm):
    class Meta:
        model = MyModel
        widgets = {
            'description': Textarea(attrs={'rows': 4, 'cols': 40}),
        }

Reference : Overriding the default field types or widgets

Upvotes: 1

Related Questions