Created
December 3, 2012 09:10
-
-
Save xfenix/4193776 to your computer and use it in GitHub Desktop.
Usage of FilteredSelectMultiple in custom models
This file contains hidden or 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.admin.widgets import FilteredSelectMultiple | |
from django import forms | |
def widget(model_reference, field, title, titlew): | |
class WidgetForm(forms.ModelForm): | |
vars()[field] = forms.ModelMultipleChoiceField(queryset=model_reference.objects.all(), | |
label=(title), | |
widget=FilteredSelectMultiple( | |
(titlew), | |
False, | |
)) | |
class Media: | |
css = { | |
'all':('/media/css/widgets.css',), | |
} | |
# jsi18n is required by the widget | |
js = ('/admin/jsi18n/',) | |
class Meta: | |
model = model_reference | |
return WidgetForm | |
This file contains hidden or 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 path.to.multiselect import widget | |
from myapp.models import MyModel | |
class MyAdminModel(admin.ModelAdmin): | |
form = widget(MyModel, 'field_name', 'Field title', 'field_widget_title', ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment