Search code examples
django-autocomplete-light

Django Autocomplete-light with mutiple apps


I'm using Python 3.4 Django 1.7. My project includes 3 applications that have similar models for example:

I have an ElectricityBill application with:

Account, Meter, Invoice models.

I also have a NaturalGasBill application with:

Account, Meter, Invoice models.

When I register my autocompletes, (Same with both applications), the second will always replace the first.. for example.. when I goto localhost/autocomplete I get this:

InvoiceAutocomplete     /autocomplete/InvoiceAutocomplete/
AccountAutocomplete     /autocomplete/AccountAutocomplete/
MeterAutocomplete   /autocomplete/MeterAutocomplete/

Obviously, there is nothing unique about these urls to indicate which application the url should apply.

Does anyone have a solution for this?


Solution

  • Found this in the documentation:

    # Extra **kwargs are used as class properties in the subclass.
    autocomplete_light.register(SomeModel,
    # SomeModel is already registered, re-register with custom name
    name='AutocompleSomeModelNew',
    # Filter the queryset
    choices=SomeModel.objects.filter(new=True))
    

    A link to the documentation is here: https://django-autocomplete-light.readthedocs.org/en/docs_rewrite/cookbook.html

    Registering the autocomplete with a custome name is exactly what I was looking for. It is unfortunate this was so difficult to find in the documentation.