Created
September 6, 2017 03:02
-
-
Save zbyte64/faaf36e2b22e81c7bdba7b25ad2aa809 to your computer and use it in GitHub Desktop.
Django select2 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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