I'm trying to implement the HTML5 colorpicker in Django's admin page.
Here is my model:
#model.py
...
class Category(models.Model):
...
color = models.CharField(max_length=7)
Here is the form:
#form.py
from django.forms import ModelForm
from django.forms.widgets import TextInput
from .models import Category
class CategoryForm(ModelForm):
class Meta:
model = Category
fields = '__all__'
widgets = {
'color': TextInput(attrs={'type': 'color'}),
}
class CategoryAdminForm(ModelForm):
form = CategoryForm
And finally the admin:
#admin.py
...
from .forms import CategoryAdminForm
...
class CategoryAdmin(admin.ModelAdmin):
form_class = CategoryAdminForm
filter_horizontal = ('questions',)
fieldsets = (
(None, {
'fields': (('name', 'letter'), 'questions', 'color')
}),
)
However, the type for the field is still text. How do I change the type for the input field to color in the admin page?