models.ForeignKey caused too many SQL queries

Is there a way to restrict the foreign key to only list one item, instead of all items in the referred-to table?

I’m guessing this is an issue with a ModelChoiceField generating the choices for the form widget.

If so, ModelAdmin.raw_id_fields is a possibility.

HTH

1 Like