0
我有一個selectfield,我重寫了我的模型中的charfield。我在場上根本不能使用外鍵。Django自定義選擇字段與初始
class AliasForm(forms.ModelForm):
account = forms.ModelChoiceField(queryset=Account.objects.all(), widget=forms.HiddenInput())
domain = forms.ModelChoiceField(queryset=Domain.objects.all(), widget=forms.HiddenInput())
end = forms.ModelChoiceField(queryset=Mailbox.objects.all())
def __init__(self, *args, **kwargs):
self.account = kwargs.pop('account', None)
super(AliasForm, self).__init__(*args, **kwargs)
if self.account:
self.fields['end'].queryset = Mailbox.objects.filter(account=self.account)
我該如何讓自動選擇的結果通過值?