﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27563	"Move ""Apply limit_choices_to"" code from BaseModelForm to fields_for_model()"	Jon Dufresne	nobody	"I frequently use `fields_for_model()` to generate form fields dynamically on a model form. The form may have different fields based on the request, system settings,  or other input. Using `fields_for_model()` is very convenient to build these dynamic fields. For the most part, it is built consistently had the field originally been defined on `Meta.fields`.

One shortfall I noticed, `limit_choices_to` is not applied to form field querysets the way it typically is for `ModelForm`s. To make the `fields_for_model()` function more convenient and consistent with fields generated by `ModelForm`, I'd like to suggest moving the ""Apply limit_choices_to"" code from `BaseModelForm` to `fields_for_model()`.

Currently here: https://github.com/django/django/blob/3507d4e773aa9ff2336e7230ba231c4ba6eb568f/django/forms/models.py#L294-L300

Suggested location: https://github.com/django/django/blob/3507d4e773aa9ff2336e7230ba231c4ba6eb568f/django/forms/models.py#L172-L173"	Cleanup/optimization	closed	Forms	1.11	Release blocker	fixed			Accepted	1	0	0	0	0	0
