1

I'm trying to figure out django_ajax_selects and struggling; either the documentation is wrong/unclear or I'm an idiot. Or both.

I'm just trying to get the basics working, and then I'll get it up to speed. I have the field displaying but there's no output when I type in any characters.

In the docs, I'm particularly confused about the admin.py and urls.py fields. I want the field to display on a user-facing template/form, not in the admin, so I would assume that part doesn't apply to me. However, if I'm supposed to modify what's there to fit what I have, I don't know with what.

Here's what I have so far:

settings.py

AJAX_LOOKUP_CHANNELS = {
  'owner' : {'model': 'auth.user', 'search_field: 'username'},
}

urls.py

   url(r'^admin/lookups/', include(ajax_select_urls)), 
#pretty much directly from the docs, but I doubt it's correct for what I'm doing.

forms.py (tried both ways to make field--not sure why one would be used over the other)

class ApplicationForm(forms.ModelForm):

    # owner = make_ajax_field(Application, 'owner', 'owner') 
    owner = AutoCompleteSelectField('owner', required=False, help_text=None)
    class Meta:
        model = Application
        fields = ['name', 'owner']

It seems pretty straightforward, except the urls.py and admin.py, so I assume that's where I went wrong?

thumbtackthief
  • 6,093
  • 10
  • 41
  • 87
  • Have you tried a fully qualified app path, 'django.contrib.auth'? Does your Application class have an FK to user? – professorDante Nov 04 '13 at 17:44
  • I'll give it a shot, but I really think the problem lies in the urls.py or admin.py, no? – thumbtackthief Nov 04 '13 at 18:20
  • 1
    I see - the docs are admin centric. Ignore them then, you don't need any admin stuff. Change your url to 'r'^/lookups/' ... and you don't need an admin.py. Other suggestions above still apply though. – professorDante Nov 04 '13 at 18:40
  • Didn't seem to help, unfortunately. Thank you for trying though. The box stays empty no matter what; I have no idea how to debug this. – thumbtackthief Nov 04 '13 at 21:56

1 Answers1

0

I had the same problem after following the documentation. Make sure you add all the required Javascript files and the jQuery files in your html. Its not mentioned in the documentation, I used the following to get it working:

<link href="/static/ajax_select/css/ajax_select.css" type="text/css" media="all" rel="stylesheet" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>

<!-- Custom styles for this template -->
<script type="text/javascript" src="/static/ajax_select/js/ajax_select.js"></script>

The ajax_select .js and .css files come with the package when you install it, you just have to make sure you are serving them correctly from your static folder so that the js and css files show up when you run the test server. I used a virtualenv and used pip to install it. Try using your dev tools from the browser to see if the files get the correct HTTP codes 200 OK or 304.

And as @professorDante said in the comments, if its not admin related, take out the admin/ from your urls.

achabacha322
  • 651
  • 10
  • 32