George Notaras avatar George Notaras committed ea64226

Widget now uses new setting for static files paths and also returns a list of tags suitable for editing in the admin (comma-delimited list by using taggit.utils.edit_string_for_tags()).

Comments (0)

Files changed (1)

src/taggit_autocomplete_modified/widgets.py

 from django.core.urlresolvers import reverse
 from django.utils.safestring import mark_safe
 
+from taggit.utils import edit_string_for_tags
 from taggit_autocomplete_modified import settings
 
 
     
     class Media:
         css = {
-            'all': ('%s/jquery.autocomplete.css' % settings.TAGGIT_AUTOCOMPLETE_CSS_BASE_URL,)
+            'all': ('%sjquery.autocomplete.css' % settings.TAGGIT_AUTOCOMPLETE_MEDIA_URL,)
         }
         js = (
-            # The jquery library should be added by your project
-            '%s/jquery.autocomplete.js' % settings.TAGGIT_AUTOCOMPLETE_JS_BASE_URL,
+            '%sjquery.min.js' % settings.TAGGIT_AUTOCOMPLETE_MEDIA_URL,
+            '%sjquery.autocomplete.js' % settings.TAGGIT_AUTOCOMPLETE_MEDIA_URL,
         )
     
     def render(self, name, value, attrs=None):
+        if value is not None and not isinstance(value, basestring):
+            # value contains a list a TaggedItem instances
+            # Here we retrieve a comma-delimited list of tags suitable for editing by the user.
+            value = edit_string_for_tags([o.tag for o in value.select_related('tag')])
         json_view = reverse('taggit_autocomplete_modified_tag_list')
         html = super(TagAutocomplete, self).render(name, value, attrs)
         js = u'<script type="text/javascript">jQuery().ready(function() { jQuery("#%s").autocomplete("%s", { multiple: true }); });</script>' % (attrs['id'], json_view)
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 ProjectModifiedEvent.java.
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.