Best approach to edit one of the widgets in the Admin site


My Django site is RTL which means all forms in the Admin site are also set as RTL.

This is fine, but not for all widgets.

For example, the email address field of Add User and Change User forms is also in RTL which is not appropriate.

I know I can edit the widgets with some code like this:

self.fields['email'].widget.attrs.update({'dir': 'ltr'})

But this works only if I use a custom form in the file, and for that I need to have an app.

One extra app for nothing but changing the text direction of just one widget in the Admin site is overkill.

Is there any other solution?

What about using a custom CSS and setting widget direction by CSS? (read also The Django admin site | Django documentation | Django)

The question is, which app I choose to override the CSS of Admin site?

It can be done at the project level. See the docs referenced above.

Also, it can be done by adding a media asset to the ModelAdmin class.

1 Like