4

AdminFormでfilter_horizo​​ntalオプションの代わりにraw_id_fieldsを使用するm2m関係があります。説明のために、レコードはすでに分類されているため、filter_horizo​​ntalオプションではなくraw_id_fieldsを使用します。そのため、ポップアップウィンドウで、ユーザーはカテゴリを介して検索およびフィルタリングすることができます。しかし、私が理解できない2つのポイントがあります。

  • ポップアップウィンドウで複数のレコードを選択する可能性
  • input_fieldにpkの代わりに実際の名前を表示する
4

2 に答える 2

0
  1. それが可能だ。複数のレコードを選択するには、またはウィジェットのクラスにスクリプトを含めて、デフォルトdismissRelatedLookupPopup()をオーバーライドする必要があります。django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.jsMediaModelAdmin

    var dismissRelatedLookupPopup = (function(prev, $) {
        return function(win, chosenId) {
            var name = windowname_to_id(win.name);
            var elem = document.getElementById(name);
    
            // 1. you could add extra condition checking here, for example
            if ($(elem).hasClass('my_raw_id_ext_cls')) { // add this class to the field
            //     ...logic of inserting picked items from the popup page
            } 
            else { // default logic
                prev(win, chosenId);
            }
    
            // 2. or you could copy the following part from RelatedObjectLookups.js ...
            if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {    
                elem.value += ',' + chosenId;
                // 2. and add a return. Remember this acts globally.
                return;
            } else {
                document.getElementById(name).value = chosenId;
            }
    
            // 3. the following line cause the popup to be closed while one item is picked. 
            // You could comment it out, but this would also affect the behavior of picking FK items.
            win.close(); 
    
        }
    })(dismissRelatedLookupPopup, django.jQuery);
    
  2. Django はデフォルトではこれをサポートしていません。djangosnippets.orgにいくつかのスニペットがあります。それらを参照してください。

于 2013-02-04T14:47:21.593 に答える
0

最後に、変更されたhttps://django-salmonella.readthedocs.org/en/latest/を使用しています。入力フィールドを表示せず、選択したレコードをテーブルに表示します。

于 2013-06-05T06:59:53.233 に答える