Anonymous avatar Anonymous committed 9dec3ca

[soc2009/admin-ui] Fix for a bug where saving m2m autocomplete fields was throwing an exception because there was a trailing comma. This also allows trailing commas on m2m raw_id_fields.

Comments (0)

Files changed (2)

django/contrib/admin/templates/widget/m2m_searchinput.html

 {% load i18n %}
-
 <a href="{{ related_url }}{{ url }}" class="related-lookup" id="lookup_id_{{ name }}" onclick="return showRelatedObjectLookupPopup(this);">
   <img src="{{ admin_media_prefix }}img/admin/selector-search.gif" width="16" height="16" alt="{% trans "Lookup" %}" />
 </a>
 <script type="text/javascript">
 $(document).ready(function() {
-    // Show lookup input
-    
     $('#id_{{ name }}').tokenInput("{{ search_path }}", {
         noResultsText: "No results found.",
         searchingText: "Searching..."

django/contrib/admin/widgets.py

 
     def value_from_datadict(self, data, files, name):
         value = data.get(name, None)
+        
+        if value and value[-1] == ',':
+            value = value[0:-1] # truncate trailing comma
+        
         if value and ',' in value:
-            return data[name].split(',')
+            return value.split(',')
         if value:
             return [value]
         return None
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.