Home

Django Admin Single Line Unlimited Input For Postgres

If you need a single line input for a CharField in django admin but want unlimited length input? Are you using postgres? Then you can use this snippet.

Unlimited input for django admin with single line input widget ยท GitHub

varchar(n) is Bad

See https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_varchar.28n.29_by_default

Why not TextArea?

Why not use TextArea? This defaults to a multiline input, and you'd need to override it for every single CharField you use.

See https://stackoverflow.com/questions/3469979/django-admin-overriding-the-widget-of-a-custom-form-field/4466958#4466958

How does it work?

We override the database used in the CharField and just use varchar, This is the same perfomance wise as varchar(n) and text.

There's also the django based python check and where we pass in sys.maxsize so we cover most possible sizes.

https://docs.djangoproject.com/en/2.2/ref/models/fields/#django.db.models.CharField.max_length

Other people who have also done this.

Jacob Kaplan-Moss also go annoyed enough to to this as well. https://github.com/jacobian/django-postgres-unlimited-varchar

Looks like he skips the size check entirely. Not knowing the internals of django admin as well as he does, I opted for letting the code run without messing with it too much.

Happy that a big name django person did this as well, reassures me that I'm thinking along the right lines