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 like a CharField
in forms (i.e. it
uses a single-line input). 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]
(https://www.postgresql.org/docs/9.1/static/datatype-character.html)).
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.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 454caabb9e75a35bbe79c3ad2d55ab7ba4cdf71ca8400973f5497b5b652f66d3 |
|
MD5 | 72adf12e5b2ce25ce3990a707b353ac3 |
|
BLAKE2b-256 | 8b7bef90c7f1fc2b752365eb87968e75c898cd252d3cf1844786993cddc74a0f |
Hashes for django_short_text_field-0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15d03cd14a9a376f21e3dca31711b81420ef0aff2fed62495094232f22ab90f6 |
|
MD5 | 2ddd933c5194cb8e1236cc0f0e29e2db |
|
BLAKE2b-256 | dc7b75ef368b3325b26f99b23be362f60ecbe0dabcea6c45613f5f00878c4e91 |