Hi all,
I've tested django-autocomplete-light in a recent project, and it works great. But I'm having trouble with figuring out a good way to implement custom querysets instead of objects.all() for my forms.
For example, I have events and users invited to events in my project. The "invite user" form should limit choices to users who are not yet attending that event. Other forms might have other, perhaps more complex queryset restrictions.
I've looked at the code a bit, and I guess it could be achieved by overriding a number of parts:
* Register a separate Autocomplete object for each variation of queryset restrictions,
* In AutocompleteModelBase.choices_for_request(), obtain the context from request.GET (for example event_id to exclude users),
* In AutocompleteInterface.get_absolute_url(), somehow get the event_id from the form/view context, and add it to the URL (haven't figured out how to do this yet).
But even if I figure out the last part, it seems a bit tedious and not at all DRY to have to add this much boilerplate for each custom queryset, when the standard django.forms.ModelChoiceField has a nice queryset argument that can be set in the form __init__ method.
Do you have any suggestions on the best approach to building autocompletes whose queryset depends on the parameters of the view that is rendering the form?
Thanks,
Mattias