2

I'm trying to get autocomplete-light working in the admin area of my app. The docs are located here:

The Foreign Key select list is dissapearing and a basic text box is appearing as expected. But the select list is not showing up.

I have installed the app and placed the appropriate include in my urls.py.

related models:

class Inventory(models.Model):
    title = models.CharField(max_length=100, db_index=True)
    product_code = models.CharField(max_length=100, db_index=True, primary_key = True)

class Customer_Order(models.Model):
    order_id = models.CharField(max_length=100, db_index=True, null = True, blank = True)
    customer_id = models.ForeignKey('inventory.Customer')
    products = models.ManyToManyField('inventory.Inventory', through='inventory.Customer_Order_Products')

class Customer_Order_Products(models.Model):
    order_id = models.ForeignKey('inventory.Customer_Order')
    product_id = models.ForeignKey('inventory.Inventory')

autocomplete_light_registry.py:

import autocomplete_light
from inventory.models import Inventory

autocomplete_light.register(Inventory, search_fields=('title',),
               autocomplete_js_attributes={'placeholder': 'city name ..'})

admin.py:

class Customer_Order_ProductsInline(enhanced_admin.EnhancedAdminMixin, admin.TabularInline):
    model = Customer_Order.products.through
    extra = 0
form = autocomplete_light.modelform_factory(Customer_Order_Products)

class Customer_OrderAdmin(enhanced_admin.EnhancedModelAdminMixin, admin.ModelAdmin):
     inlines = (Customer_Order_ProductsInline, OrderStatusInline )  

My own debugging:

  • I've gone to /autocomplete/ and found the registered list of Inventory titles, however it is not complete. It is only showing about 20 of them out of 155.

  • I've made sure that the proper files are being loaded in the html. All of the includes appear to be showing up. I get a 304 code in the terminal for all of them, but I think this is okay. The only thing I can't seem to ensure that is being loaded is the link to jquery. I found the link to the script in the header of the html source, and checked the link (https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js) which appears to work.

UPDATED **

  • I just found this error in the web developer error console: TypeError: 'undefined' is not a function (evaluating '$(this).yourlabsWidget()') in widget.js on line 297. This shows that at least widget.js is being loaded.

  • And finally, when I update an existing Customer_Order, the blank field shows up NEXT to the regular foreign key pull down. Not inplace of it. I have no idea why this is happening.

I was hoping someone has either had a similar issue, or has some debugging advice. I'm fairly new to Django and my debugging skills are lacking at best.

HTML:

<!DOCTYPE html>
<html lang="en-us" >
<head>
<title>Add Customer Order | Art & Fibre</title>
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css" />
<!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="/static/admin/css/ie.css" /><![endif]-->

<script type="text/javascript">window.__admin_media_prefix__ = "/static/admin/";             </script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript" src="/static/autocomplete_light/autocomplete.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/widget.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/addanother.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/text_widget.js"></script>
<script type="text/javascript" src="/static/autocomplete_light/remote.js"></script>
<link rel="stylesheet" type="text/css" href="/static/autocomplete_light/style.css" />

then later on..

<span class="autocomplete-light-widget customer_order_products_set-0-product_id
single"
id="id_customer_order_products_set-0-product_id-wrapper"
data-max-values="1" data-bootstrap="normal"
data-autocomplete-url="/autocomplete/InventoryAutocomplete/" data-autocomplete-choice-selector="[data-value]" data-autocomplete-placeholder="Product name .."
>
Jglstewart
  • 696
  • 1
  • 8
  • 16

1 Answers1

0

So I am also new to Django and the autocomplete-light toolbar, but I got it to work for me. A couple of things for debugging:

  • Firefox plus Firebug was really useful to me. You can see exactly what is being loaded in real time in your page for javascript and html. (so you can see what autocomplete-light queries are being made as you type in the box)
  • Django-debug-toolbar was also really useful. You can see what queries are being made to your database.
  • I can't tell from the code snippets you posted, but did you include the following in your admin/base_site.html or customer_order/index.html template?

    {% include 'autocomplete_light/static.html' %}

  • You also seem to be missing this at the end of your admin.py file:

    admin.site.register(Customer_Order, Customer_OrderAdmin)

user
  • 4,651
  • 5
  • 32
  • 60
  • Thanks for your time! I'm using the Safari developer tool. As far as I can tell, everything is being loaded. But the queries arn't causing any requests. Ie: Nothing happens at all when I type into the text field (blank by the way, not even the place holder is showing up). I can't seem to get past the one undefined function error. Which the function couldn't be getting called if widget.js is not being loaded. Anyway, I guess I wasn't extremely clear. But not to worry, I've registered my admin. – Jglstewart Dec 31 '12 at 06:49
  • One thing that I would check is that the js file is being loaded properly--it might be in the wrong directory. When you check the page source, you need to see this – user Jan 05 '13 at 16:24
  • Everything is being loaded. I'll update the question with the html to show this fact. Also unless there is some javascript magic that is occuring here. It is impossible to receive an error on a line of a code that is not being loaded. In other words, if widget.js wasn't being loaded, it wouldn't be able to attempt to call the function. – Jglstewart Jan 06 '13 at 16:47
  • Also, I've been using this javascript debugger inside of widget.js to attempt to debug the problem. (Another proof that the files are being loaded). – Jglstewart Jan 06 '13 at 16:58