0
我有一個表單,其中一個選擇輸入的選項與另一個表相關。Django 1.9不過濾查詢結果
一切完美,但知道我要排除一些選項,讓我在forms.py以下科德:
class employeesForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(employeesForm, self).__init__(*args, **kwargs)
self.fields['num_employee'].required = False
self.fields['id_ignition'].required = False
self.fields['picture'].required = False
self.fields['source'].required = False
class Meta:
model = Employees
ccOptions = CostCenter.objects.all().values_list('id_costCenter', 'area')
jcOptions = JobCode.objects.all().values_list('id_jobCode', 'gmpName')
ntOptions = Nations.objects.all().values_list('nationality')
esOptions = EmpSources.objects.all().values_list('source')
from django.db.models import Q
# in this line
stOptions = Status.objects.exclude(Q(id_status=2) | Q(id_status=3)).values_list('status')
fields = [
'num_employee',
'fullName',
'shortName',
'gender',
'birthday',
'initday',
'id_status',
'nationality',
'picture',
'source',
]
widgets = {
'num_employee': forms.NumberInput(attrs={'class': 'form-control', 'name': 'num_employee'}),
'fullName': forms.TextInput(attrs={'class': 'form-control', 'name': 'fullName', 'placeholder': 'Angel Rafael Ortega Vazquez'}),
'shortName': forms.TextInput(attrs={'class': 'form-control', 'name': 'shortName', 'placeholder': 'Rafael Ortega'}),
'gender': forms.CheckboxInput(attrs={'class': 'form-control', 'name': 'gender'}),
'birthday': forms.DateInput(attrs={'class': 'form-control', 'name': 'birthday'}),
'initday': forms.DateInput(attrs={'class': 'form-control', 'name': 'initday'}),
# also here
'id_status': forms.Select(choices=stOptions, attrs={'class': 'form-control', 'name': 'id_status'}),
'nationality': forms.Select(choices=ntOptions, attrs={'class': 'form-control', 'name': 'nationality'}),
'picture': forms.ClearableFileInput(attrs={'class': 'form-control', 'name': 'picture'}),
'source': forms.Select(choices=esOptions, attrs={'class': 'form-control', 'name': 'source'}),
}
的問題是,即使在排除選項,我選擇渲染劇照完整的表格。
我甚至嘗試過濾只有一個參數,但結果是一樣的。 我也刪除了我的瀏覽器緩存,只是爲了放棄這種可能性,但並沒有改變。
謝謝你,你不僅回答了我的問題,但你也糾正什麼香港專業教育學院一直在做錯誤的,在我的表單字段選擇屬性。 – Izuzvo