Ticket #5372: newforms-admin-query-caching.diff

File newforms-admin-query-caching.diff, 1.0 KB (added by anonymous, 7 years ago)
  • django/contrib/admin/options.py

    === modified file 'django/contrib/admin/options.py'
     
    661661        self.parent_model = parent_model
    662662        self.opts = self.model._meta
    663663        # TODO: pass a fields arg into forms.inline_formset if/when we have one
    664         self.formset_class = forms.inline_formset(parent_model, self.model, fk_name=self.fk_name, formfield_callback=self.formfield_for_dbfield, extra=self.extra)
     664       
     665    def formfield_for_dbfield(self, db_field, **kwargs):
     666        if isinstance(db_field, models.ForeignKey):
     667            kwargs['cache_choices'] = True
     668        return super(InlineModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
     669           
     670    def _formset_class(self):
     671        return forms.inline_formset(self.parent_model, self.model, fk_name=self.fk_name, formfield_callback=self.formfield_for_dbfield, extra=self.extra)
     672    formset_class = property(_formset_class)
    665673
    666674    def fieldsets(self, request):
    667675        """
Back to Top