A simple django widget that appends a character count to a text input which is determined by the max_length
of that particular field. This only works on text inputs and not text areas (as they don't respect max_length
anyway)
There are a few ways of setting a widget for a form field
from django import forms
from charsleft_widget.widgets import CharsLeftInput
class ExampleForm(forms.Form):
name = forms.CharField(widget=CharsLeftInput())
or
from django import forms
from charsleft_widget.widgets import CharsLeftInput
class ExampleForm(forms.Form):
name = forms.CharField()
def __init__(self, *args, *kwargs):
super(ExampleForm, self).__init__(*args, **kwargs)
self.fields['name'].widget = CharsLeftInput
from django.contrib import admin
class ExampleAdmin(admin.ModelAdmin):
# Use widget on all instances of this form field
formfield_overrides = {
models.TextField: {'widget': CharsLeftInput},
}
or
from django.contrib import admin
class ExampleAdmin(admin.ModelAdmin):
pass
# Use widget on particular instances of the form field
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name is 'name':
kwargs['widget'] = CharsLeftInput
return super(ContentObjectAdmin,self).formfield_for_dbfield(db_field,**kwargs)