Caching queryset choices for ModelChoiceField or ModelMultipleChoiceField in a Django form
问题 When using ModelChoiceField or ModelMultipleChoiceField in a Django form, is there a way to pass in a cached set of choices? Currently, if I specify the choices via the queryset parameter, it results in a database hit. I'd like to cache these choices using memcached and prevent unnecessary hits to the database when displaying a form with such a field. 回答1: You can override "all" method in QuerySet something like from django.db import models class AllMethodCachingQueryset(models.query.QuerySet