Ich habe ein Formular, wo die Optionen einer meiner Select-Eingabe zu einer anderen Tabelle verwandt sind.Django 1.9 filtert keine Abfrageergebnisse
Alles funktioniert perfekt, aber ich weiß, einige Optionen ausschließen wollen, so kann ich die folgende kode in forms.py haben:
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'}),
}
Das Problem ist, dass selbst mit der Option ausschließen, meine wählen Stills Rendering die komplette Tabelle.
Ich habe sogar versucht, nur einen Parameter zu filtern, aber das Ergebnis ist das gleiche. Ich löschte auch meinen Browser-Cache, nur um diese Möglichkeit zu verwerfen, aber es hat sich nicht geändert.
danke, Sie nicht nur meine Frage beantwortet, sondern auch korrigierte Sie, was ive in meinen Formularfeldern mit der Wahl Attribute falsch gemacht hat. – Izuzvo