Is there some way to make the following possible, or should it be done elsewhere?
class JobRecordForm(forms.ModelForm):
supervisor = forms.ModelChoiceField(
queryset = User.objects.filter(groups__name='Supervisors'),
widget = forms.RadioSelect,
initial = request.user # is there some way to make this possible?
)
class Meta:
model = JobRecord
If you do this in your view.py instead:
form = JobRecordForm( initial={'supervisor':request.user} )
Then you won't trigger the validation.
See http://docs.djangoproject.com/en/dev/ref/forms/api/#dynamic-initial-values
You might want to handle this in your view function. Since your view function must create the initial form, and your view function knows the user.
form = JobRecordForm( {'supervisor':request.user} )
This will trigger validation of this input, BTW, so you can't provide hint values this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With