All foreign keys to ContentType should use robust filtering for limit_choices_to #3892
Labels
status: accepted
This issue has been accepted for implementation
type: housekeeping
Changes to the application which do not directly impact the end user
Proposed Changes
Ensure that all model fields equating to
ForeignKey(to=ContentType)
wherelimit_choices_to
is in use employ robust filtering by both app and model name.Justification
There are several models in NetBox which have one or more ForeignKey fields to ContentType and utilize
limit_choices_to
to constrain the available choices. In all instances where the set of ContentTypes is constrained, a concise list of (app, model) pairings should be used. For example, the Cable model currently has:This is problematic, because it allows for a potential name collision across apps within NetBox. Although not currently an issue, we would do well to address this before it presents a problem.
The above instance should be changed to use the
model_names_to_filter_dict()
and an explicit list of (app, model) pairings to filter the field's associated queryset:This change also entails extending the
model_names_to_filter_dict()
function to match on bothapp_label
andmodel
; it currently matches only onmodel
. A set ofQ
objects can be used to achieve this.The text was updated successfully, but these errors were encountered: