Germano Gabbianelli avatar Germano Gabbianelli committed 9887e7e is now always a string.

Comments (0)

Files changed (1)


 import operator
 from django.core.urlresolvers import reverse
-from django.db import models
 from django.http import Http404, HttpResponse, HttpResponseForbidden
 from django.utils import simplejson
 from django.utils.encoding import smart_str = id
         self.current_app = current_app
-        if isinstance(id, models.Field):
+        from django.db.models.fields.related import RelatedField
+        if isinstance(id, RelatedField):
             self.field = id
             self.model =
-            opts = self.field.model._meta
-            self.path = '/'.join((opts.app_label, opts.module_name,
+            opts = self.field.related.opts
+   = '.'.join((opts.app_label, opts.module_name,
             if self.queryset is None:
                 self.queryset = self.model._default_manager.complex_filter(
                 self.key = self.field.rel.get_related_field().name
             if self.reverse_label is None:
                 self.reverse_label = True
-        else:
+        elif isinstance(id, (str, unicode)):
             self.field = None
             self.model = self.queryset.model
-            self.path = id.replace('.', '/')
+   = id
             if self.key is None:
                 self.key = 'pk'
             if self.reverse_label is None:
                 self.reverse_label = False
+        else:
+            raise TypeError("id should be either a related field or a string: %r" % id)
+        self.path = id.replace('.', '/')
         def build_func(attr):
             if attr in self.model._meta.get_all_field_names():
     def register(self, id, settings_class=AutocompleteSettings, **options):
         id = getattr(id, 'field', id)
         if id in self.settings:
-            id = self.settings[id].path.replace('/', '.')
+            id = self.settings[id].id
             raise AlreadyRegistered('%r is already registered' % id)
         self.settings[id] = settings = settings_class(id,, **options)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.