Django adminで、フォームが保存されたときにFilteredSelectMultipleウィジェットから選択した値を取得する方法を知っている人はいますか?
class ControllerForm(forms.ModelForm):
terminal = forms.ModelMultipleChoiceField(queryset=[])
def __init__(self, *args, **kwargs):
super(ControllerForm, self).__init__(*args, **kwargs)
self.fields['terminal'].widget = widgets.FilteredSelectMultiple('terminals', False)
self.fields['terminal'].help_text = "Select the terminals which are to be added to the group."
self.fields['terminal'].required = False
self.fields['terminal'].label = "Select terminal(s)"
self.fields['terminal'].choices = [(t.id, str(t)) for t in Terminal.objects.filter(associated=False)]
class Meta:
model = Controller
class ControllerAdmin(admin.ModelAdmin):
"""
Controller admin form customization.
"""
list_display = ('name', 'group',)
form = ControllerForm
admin.site.register(Controller, ControllerAdmin)
編集:save_modelメソッドの値にアクセスできると思います。(https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model)