For a long time we've been overriding our ModelAdmin's formfield_for_foreignkey
to limit the queryset the field can choose from. Here's a simplified version of what I mean:
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "site":
if not request.user.is_superuser:
kwargs["queryset"] = request.user.site
But I recently added this field to the autocomplete_fields
definition (to get some Select2 gravy). The result was I now see no suggestions as a non-superuser account.
Is there a more right way to limit the queryset, or is this a simple bug in Django?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…