[Fixed]-Django: Set default widget in model definition

11👍

Is it possible to set a custom widget for a model in the model definition?

Yes, if you override the field: Specifying the form field for a model field.

👤jpic

0👍

For reference, based on formfield proposed in earlier answer:

    def formfield(self, **kwargs):
        kwargs['widget'] = CurrencyWidget
        return super().formfield(**kwargs)

Leave a comment