Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lookup channels from third-party apps #98

Closed
peterfarrell opened this issue Dec 29, 2014 · 3 comments
Closed

Support lookup channels from third-party apps #98

peterfarrell opened this issue Dec 29, 2014 · 3 comments

Comments

@peterfarrell
Copy link

We have some internal third party apps that we use in other apps in our eco system. The problem is that the AJAX_LOOKUP_CHANNELS is required to be in the settings.py in order for it to work and that means we constantly have to copy those channels in our main app and keep them up to date. So we wrote:

https://github.com/peterfarrell/django-ajax-selects-autodiscover

This allows us to autodiscover any channels in installed apps by looking for a AJAX_LOOKUP_CHANNELS in each lookup.py.

In your settings.py file, replace your AJAX_LOOKUP_CHANNELS with:

from ajax_selects_autodiscover import AutoDiscover

AJAX_LOOKUP_CHANNELS = AutoDiscover()

The lookup.py files is now where you define all your channels. Here is an example:

from ajax_select import LookupChannel

from login.models import Application


class ApplicationLookup(LookupChannel):
    model = Application

    def get_query(self, q, request):
        return Application.objects.find_active_by_name(q)


AJAX_LOOKUP_CHANNELS = {
    'application': ('shared.lookup', 'ApplicationLookup'),
}
@peterfarrell
Copy link
Author

Would you accept a PR for this? It would be backwards compatible because they don't have to use AutoDiscover(). I'm fine if you'd rather keep this as a third-party add-on if you want.

@crucialfelix
Copy link
Owner

That does sound flexible. I like it !

I'm not sure it even needs to import the AutoDiscover in settings.
I would be comfortable allowing it to default to auto discover.

there are cases where I have had multiple apps installed that had lookups but I did not want them all enabled for a site. but then I would just set AJAX_LOOKUP_CHANNELS in the main settings and this would disable auto discover.

@peterfarrell
Copy link
Author

I was thinking it would be great if it was automatic, but then I thought it possibly could break backwards compatibility. If you are ok with possibly breaking that, then I can do a PR that would do it automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants