Skip to main content

An extension of the default TextInput widget that displays a read-only string prefix

Project description

django-prefixed-textinput

An extension of the default TextInput widget that displays a read-only string prefix over the input field.

Screenshot showing widget in the Django admin

Compatibility

The widget has been tested on all Python/Django version combinations officially supported by the Django project:

Django 4.2 5.0 5.1 5.2
Python 3.8
3.9
3.10
3.11
3.12
3.13
3.14

If you need to use django-prefixed-textinput with Django 3, please use a version of the package prior to 1.0.0.

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 Custom Properties ("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.

Run the extremely basic test suite across environments using tox:

$ tox run

Issues, Suggestions, Contributions

...are welcome on GitHub. Thanks for your interest in django-prefixed-textinput!

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

django_prefixed_textinput-1.0.2.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file django_prefixed_textinput-1.0.2.tar.gz.

File metadata

File hashes

Hashes for django_prefixed_textinput-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c88f66454d1aa7cb518b100b96647e663854a06f737114c3a7ced3d7d2c7ce92
MD5 c8d3add7acc46389d0ecdc8084ef745e
BLAKE2b-256 cf8f5bc42d1dcdfc84444130014d5f763ab26adb66eecc7c5a3f6d321ab484b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page