I have form for adding data in database and I want to restrict foreign key choices in my dropdown menu. It have to be restricted on my finishDate field. If finishDate is dat
You can filter it in the __init__
import datetime
def NetForm(forms.ModelForm):
#...fields
def __init__(self, *args, **kwargs):
super(NetForm, self).__init__(*args, **kwargs)
# Now set the queryset...
self.fields['idAccount'].queryset = Account.objects.filter(finishDate__gte=datetime.datetime.now())