An extension of the default TextInput widget that displays a
Project description
django-prefixed-textinput
An extension of the default TextInput
widget that displays a read-only string prefix over the input field.
Compatibility
The widget has been tested on Django 3.2 and 4.0 on Python 3.8, though I expect it to be fairly compatible with other versions given the simplicity of the implementation. For now, the package is marked as requiring Python 3.6 or higher.
Styling for the widget includes support for right-to-left (RTL) languages so this should work more or less as expected. Note that IE11 is not supported as the widget styling requires support for CSS Variables.
Installation
$ pip install django-prefixed-textinput
Usage
Add prefixed_textinput
to your INSTALLED_APPS
setting:
INSTALLED_APPS = [
# ...
'prefixed_textinput',
]
Import the widget:
from prefixed_textinput import PrefixedTextInput
Define a custom admin form, which allows overriding the widget for a specific field:
# forms.py
from django import forms
from prefixed_textinput import PrefixedTextInput
class MyModelAdminForm(forms.ModelForm):
class Meta:
widgets = {
'myfield':
PrefixedTextInput(prefix='FOO'),
}
fields = '__all__'
Specify the custom admin form in your admin definition:
# admin.py
from django import admin
from .forms import MyModelAdminForm
from .models import MyModel
@admin.register(MyModel)
class ProductAdmin(admin.ModelAdmin):
form = MyModelAdminForm
Development
If working locally on the package you can install the development tools via pip
:
$ pip install -e .[dev]
Run the bundled Django example project:
$ cd example_project
$ python manage.py migrate
$ python manage.py createsuperuser
$ python manage.py runserver 0.0.0.0:8000
$ open http://localhost:8000/admin/
Navigate to the example Book
model in the Bookshop
app to see the widget in action.
To lint with flake8
:
$ flake8
Issues, Suggestions, Contributions
...are welcome on GitHub. Thanks for your interest in django-prefixed-textinput
!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-prefixed-textinput-0.1.1.tar.gz
.
File metadata
- Download URL: django-prefixed-textinput-0.1.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7de16d9ffb1b2f51a262493ed030f225b125d362804189ad3aded8f2c7576fd0 |
|
MD5 | 9efda3675146d64cb85a1ea2d50632bc |
|
BLAKE2b-256 | 1949f940ed6dec4c729c774fe4683beaba2dd97a5b2f53576838886a7af71b79 |