yourlabs / django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v4 alpha, v3 stable, v2 & v1 deprecated.
https://django-autocomplete-light.readthedocs.io
MIT License
1.8k stars 467 forks source link

Facing problem in implemention (especially template-related) #444

Open AvadootNachankar opened 9 years ago

AvadootNachankar commented 9 years ago

settings.py

INSTALLED_APPS = (
    'autocomplete_light',  # the very first line
    ...
)

urls.py

from django import VERSION as django_version
if django_version < (1, 7):
    # import autocomplete_light
    import autocomplete_light.shortcuts as acl  # after referring test_project
    acl.autodiscover()

# Also kept these lines above all views' import statements

urlpatterns = patterns('',
    url(r'^$', home),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^autocomplete/', include('autocomplete_light.urls')),
    ...

autocomplete_light_registry.py

from autocomplete_light import shortcuts as acl_shortcuts

acl_shortcuts.register(ClassA)

forms.py

from autocomplete_light import shortcuts as acl_shortcuts

class ClassA(acl_shortcuts.ModelForm):
   ...

base_template.html

    ...
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    {% include 'autocomplete_light/static.html' %}
    ...

But then I stuck with template related changes which are mentioned over here. I don't know how to go ahead.

template.html - I'm rendering field on template in the following manner:

                  <div class="form-group">
                      <label class="control-label col-sm-4 {{form-name.field-name.css_classes}}" for="{{cf.field-name.id_for_label}}"> {{ cf.field-name.label }}</label>
                      <div class="col-sm-4">
                          {{form-name.field-name|addcss:"form-control"}}
                          <span class="error">{{form-name.field-name.errors}}</span>
                      </div>
                  </div>

Your help is greatly appreciated, also it would be nice if you can give a small demo because your demos were not working when I given a try (facing problem in database setup required for test project to run after running command: _./manage.py citieslight).

jpic commented 9 years ago
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

You can't use any more recent version can you ?

But then I stuck with template related changes which are mentioned over here. I don't know how to go ahead.

Open static.html, you see that it's just trying to load some JS. If the JS is loaded in your page that it should work. Else, there might be some JS error in some browser version, in that case, paste browser version and JS error.

demos were not working when I given a try (facing problem in database setup required for test project to run after running command: ./manage.py cities_light).

Define not working, post commands, outputs, tracebacks, versions please.

AvadootNachankar commented 9 years ago
from autocomplete_light import shortcuts as acl_shortcuts
class ClassA(acl_shortcuts.ModelForm)
   ...
==============

import autocomplete_light
class ClassA(autocomplete_light.ModelForm):
   ...
xyz = models.ForeignKey(XYZ)
abc = models.ForeignKey(ABC, null=True, blank=True)
jpic commented 9 years ago

Tests are run against jquery-2.1.4.js For Django 1.9 support, you should use autocomplete_light.shortcuts. Is there anywhere left in the docs or example code that led you to think otherwise ? There is no extra template code to add for the autocomplete to work, but if you want it to be fancy then you may.