sehmaschine/django-grappelli — pull request #371 by arski (2013-09-13 17:17:02+00:00)
Title: Allow models to implement an autocomplete_term_adjust function for alternative lookups

Hi, the motivation for this PR is that I want to have a URL-based autocomplete field, but with millions of URLs in the DB, and the URL field too large for indexing (not using Django's standard 200 chars, rather the web specification maximum), so lookups on it take ages.. Accordingly, I would like the autocomplete to take the user-entered URL, convert it to a hash and then perform a lookup on a nicely indexed url_hash field in the DB.

These are my model method that go together with the PR:

@staticmethod
def autocomplete_term_adjust(term):
return hashlib.sha1(term).hexdigest()

@staticmethod
def autocomplete_search_fields():
return ("url_hash__iexact",)

This is just for feature request purposes - let me know if you find this acceptable and I'll add commits for documentation and/or anything else you want fixed.

Cheers,
Martin