5.8. Admin Widget
from django import forms
from django.db import models
from django.contrib import admin
from emoji_picker.widgets import EmojiPickerTextInput, EmojiPickerTextarea
from shop.models import Customer
@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
formfield_overrides = {
models.ManyToManyField: {'widget': forms.CheckboxSelectMultiple},
models.CharField: {'widget': EmojiPickerTextInput},
models.TextField: {'widget': EmojiPickerTextarea},
# models.TextField: {'widget': Textarea(attrs={'cols': 40, 'rows': 4})},
}
5.8.1. Changeform
>>>
... @admin.register(Customer)
... class CustomerAdmin(admin.ModelAdmin):
... def get_changeform_initial_data(self, request):
... return {
... 'when': date.today(),
... 'reporter': request.user.pk
... }
5.8.2. Use Case - 1
python -m pip install django-emoji-picker
INSTALLED_APPS += ['emoji_picker']
>>>
... from emoji_picker.widgets import EmojiPickerTextInputAdmin, EmojiPickerTextareaAdmin
...
...
... class YourModelForm(forms.ModelForm):
... short_text = forms.CharField(widget=EmojiPickerTextInputAdmin)
... long_text = forms.CharField(widget=EmojiPickerTextareaAdmin)
5.8.3. Use Case - 2
python -m pip install django-emoji-picker
INSTALLED_APPS += ['emoji_picker']
>>>
... from django.db import models
... from django.contrib import admin
... from emoji_picker.widgets import EmojiPickerTextInput, EmojiPickerTextarea
... from shop.models import Customer
...
...
... @admin.register(Customer)
... class CustomerAdmin(admin.ModelAdmin):
... formfield_overrides = {
... models.CharField: {'widget': EmojiPickerTextInput},
... models.TextField: {'widget': EmojiPickerTextarea},
... }