A Django app which adds a ShortTextField model field, whichis like a TextField in the database but uses the TextInputrather than the Textarea widget in forms.
Project description
Short Text Field for Django
A very simple Django app that adds a ShortTextField
model field class, which
is treated like a TextField
in the database (i.e. the data is stored in the
database with the text
rather than the varchar
type, and the developer does
not need to specify a max_length
), but uses the TextInput
widget (a single-
line <input type="text>
) by default rather than Textarea
. This is ideal for
PostgreSQL, which recommends the 'text' type in a wider variety of
circumstances than other commonly-used database backends (see the
PostgreSQL docs).
Usage
-
Add
'short_text_field'
to yourINSTALLED_APPS
setting like this:INSTALLED_APPS = [ ... 'short_text_field', ]
-
Add a
ShortTextField
to a model like this:from short_text_field.models import ShortTextField ... class ExampleModel(models.Model): ... example_field = ShortTextField
-
A model with a
ShortTextField
should be registered in the admin site usingshort_text_field.admin.ModelAdmin
.admin.site.register(ExampleModel, short_text_field.admin.ModelAdmin)
A subclass of this class will also work:
class ExampleModelAdmin(short_text_field.admin.ModelAdmin): model = ExampleModel ... admin.site.register(ExampleModel, ExampleModelAdmin)
If you have a hierarchy of
ModelAdmin
subclasses, you can still incorporateshort_text_field.admin.ModelAdmin
easily as a mixin:class ExampleModelAdmin2(short_text_field.admin.ModelAdmin, ExampleModelAdmin1): model = ExampleModel ... admin.site.register(ExampleModel, ExampleModelAdmin)
You can also use a subclass of
short_text_field.admin.AdminSite
for the site, which will makeshort_text_field.admin.ModelAdmin
the defaultModelAdmin
subclass to use for registering. In the simplest case, you can just set thedefault_site
attribute of theAdminConfig
class and then register all of your models in the normal way:from django.contrib.admin import apps import short_text_field.admin.AdminSite ... class ExampleAdminConfig(apps.AdminConfig): ... default_site = short_text_field.admin.AdminSite
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-short-text-field-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c7c7c5b83d2ff263f9a0553ce37cddbe20ba46e330133e2ad46dae9a3efd18b |
|
MD5 | f5c3778df05b3fa74ec097d4434749c9 |
|
BLAKE2b-256 | ab8b6699445c3993be5a12ae7e2d689c26c71d431dbfa0982f3c4d8dc8670015 |
Hashes for django_short_text_field-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86a470cf717ac187a6aee0bb7ee39812d1234984f5683f3675fb1912ffaaf830 |
|
MD5 | 651b060467afd3af66f6dbca7bb5aaab |
|
BLAKE2b-256 | f89e38ecb6417d806966e622b3dd948bff7f6905442cdab759895f5b3b1ee4a3 |