Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Django select2 example
from django.contrib import admin
from .models import Blog
from .fields import UserSelectWidget
class BlogForm(forms.ModelForm):
class Meta:
model = Blog
exclude = []
widgets = {
'publisher': UserSelectWidget,
}
class BlogAdmin(admin.ModelAdmin):
form = BlogForm
admin.site.register(Blog, BlogAdmin)
from django.conf import settings
from django_select2.forms import ModelSelect2MultipleWidget, ModelSelect2Widget
from django.contrib.auth.models import User
class UserSelectWidget(ModelSelect2Widget):
model = User
search_fields = [
'username__icontains',
'email__icontains'
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment