Hi there again,
is it somehow possible to have a form with a ModelChoice field, but override its queryset by a filtered quersyset when instantiating the form?
Example:
If i have this in my forms.py:
class AddLockingAuthorisationForm(LockingAuthorisationForm):
key = forms.IntegerField(widget=forms.HiddenInput, required=False, label="")
room = forms.ModelChoiceField(queryset=Rooms.objects.all(),
required=False,
widget=forms.CheckboxSelectMultiple(attrs={
'class': "fw-bold border border-1 border-black m-1 mb-2",
}))
and what i have in mind is something like this:
if 'mail_add' in request.POST:
key = Keys.objects.get(pk=request.POST.get('mail_add')).pk
room = Rooms.objects.exclude(lockingauthorisations__key_id=key)
formdata = {'key': key, 'room': room}
…of course THIS doesn’t work, otherwise i would not post it here