15
You question might be a dupe of this.
S. Lott‘s answer there is the ticket to solve your problem.
He answered:
ForeignKey is represented by django.forms.ModelChoiceField, which is a ChoiceField whose choices are a model QuerySet. See the reference for ModelChoiceField.
So, provide a QuerySet to the field’s queryset attribute. Depends on how your form is built. If you build an explicit form, you’ll have fields named directly.
form.rate.queryset = Rate.objects.filter(company_id=the_company.id)
If you take the default ModelForm object,form.fields["rate"].queryset = ...
This is done explicitly in the view. No hacking around.
49
try something like this in the view
form = BikeForm()
form.fields["made_at"].queryset = Factory.objects.filter(user__factory)
modify the Factory queryset so that it identifies the factory which the user works at.
- [Django]-Django: How to manage development and production settings?
- [Django]-Disable a method in a ViewSet, django-rest-framework
- [Django]-Django urls without a trailing slash do not redirect
0
Nowaday, you should use:
form.base_fields['alumno_item'].queryset = AlumnoItem.objects.prefetch_related(
'alumno',
'alumno__estudiante',
'alumno__estudiante__profile',
'item'
)
- [Django]-Running ./manage.py migrate during Heroku deployment
- [Django]-How to create a unique slug in Django
- [Django]-Consolidating multiple post_save signals with one receiver