Skip to main content

Counter Widget

Counter Widget is a simple widget made up of two buttons and a number input. Two buttons are used to increase and decrease the input value.

Installation

In terminal:

pip install django-counter-widget

Add the app in your INSTALLED_APPS settings

INSTALLED_APPS = [
    ...
    'counter_widgets',
]

How To Use

You can use the CounterWidget for your forms IntegerField.

from counter_widgets import CounterWidget

class YourForm(forms.Form):
    counter_field = forms.IntegerField(widget=CounterWidget)

In the template where you are rendering YourForm, include the following line

{{ form.media }}

where "form" is the name of the context variable that refers to the form containing the counter widget. If you do not include the above line in the template, the increase (+) and decrease (-) buttons will not work. {{form.media}} will add the following line in the rendered HTML

<script src="/static/counter_widgets/js/counter.js"></script>

Customising the Widget

You can create your own customized widget from Counterwidget. You can change increment text, decrement text, delta (increment/decrement amount default is 1), you can have different values ​​for increment and decrement. In the following we have customized counter widget increment_text, decrement_text, increment_value, decrement_value

class TestForm(forms.Form):
    count = forms.IntegerField(widget=CounterWidget(
        increment_text="Add 100",
        decrement_text="Subtract 50",
        increment_value=100,
        decrement_value=50))

Another example

class TestForm(forms.Form):
    count = forms.IntegerField(widget=CounterWidget(delta=100))

Metadata

Release files for django-counter-widget 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-counter-widget 1.1
File Size Uploaded Provenance
django-counter-widget-1.1.tar.gz 3.9 kB Without provenance Details

Release files / django-counter-widget-1.1.tar.gz

Download URL django-counter-widget-1.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
47eec522a5bb80da8df8dfeedb13d2c44ef9a64f4708b73a8229c7989eeb98c8
BLAKE2b-256 checksum
How to use checksums
a932d2762bfc41fcee33177ef854bcccdb759c060a413416ee49242797697ce3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Security for django-counter-widget 1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page