简体   繁体   English

Django Admin StackedInline未加载添加其他模型,未捕获的TypeError:无法读取未定义的属性'fn'

[英]Django Admin StackedInline Not Loading Add Another model, Uncaught TypeError: Cannot read property 'fn' of undefined

When I add a number of inlines to my django admin as shown below the Add another {model name} disappears. 当我向django admin添加许多内联时,如下所示,“ Add another {model name}消失了。 If I check the javascript console I see that I am getting the following error: 如果我检查JavaScript控制台,会看到以下错误:

Uncaught TypeError: Cannot read property 'fn' of undefined 未捕获的TypeError:无法读取未定义的属性'fn'

at inlines.js:20 在inlines.js:20

at inlines.js:295 在inlines.js:295

Here's my Django admin: 这是我的Django管理员:

@admin.register(models.Paper)
class PaperAdmin(BaseLiteratureAdmin):

    class EditedPaperAdminInline(admin.StackedInline):
        model = models.EditedPaper
        extra = 0

    class SupplementaryInformationAdminInline(admin.StackedInline):
        model = models.SupplementaryInformation
        extra = 0

    class PaperNotesAdminInline(BaseNotesAdminInline):
        exclude = tuple(
            i for i in BaseNotesAdminInline.exclude if i != 'paper'
        )

    class ReferencedPaperInline(admin.StackedInline):
        model = models.Paper.referenced_papers.through
        extra = 0
        fk_name = 'from_paper'
        verbose_name = "Referenced Paper"
        verbose_name_plural = "Referenced Papers"

    inlines = (
        EditedPaperAdminInline, # problem
        PaperNotesAdminInline, # ok single/together
        ReferencedPaperInline, # ok single/together
        SupplementaryInformationAdminInline, # problem

    )

Here's what I'd like to see: 这是我想看到的: 管理员可以添加新模型

Here's what I'm seeing: 这是我所看到的: 在此处输入图片说明

And I found the solution--it's to change the order of the inlines in the inlines list, like so: 我找到了解决方案-更改内inlines列表中内inlines的顺序,如下所示:

inlines = (
        PaperNotesAdminInline, # ok single/together
        ReferencedPaperInline, # ok single/together
        EditedPaperAdminInline, # problem
        SupplementaryInformationAdminInline, # problem

    )

The #comments next to each inline note that the PaperNotesAdminInline and ReferencedPaperInline are both 'OK' in that the Add another {model name} link still appears if they are included. 每个内联代码旁边的#comments指出PaperNotesAdminInlineReferencedPaperInline都为“ OK”,因为如果包括它们,则“ Add another {model name}链接仍会出现。 The other two inlines, if added in order shown in the admin model definition, result in the JavaScript error and the links disappearing for each inline. 如果按照管理模型定义中显示的顺序添加其他两个内联,则会导致JavaScript错误,并且每个内联的链接都会消失。 However, if I change the order to the second inlines list, everything loads correctly. 但是,如果我将顺序更改为第二个内inlines列表,则将正确加载所有内容。

What is going on here? 这里发生了什么?

I has same problem on my project, on a large rich form script inline.js loads before jQuery and produces an error. 在我的项目中,在大型富格式脚本inline.js在jQuery之前加载并产生错误时,我遇到了同样的问题。 I added changed inline.js to my project folder, it checks are jQuery loaded, and if not, it waits for 300 ms, and tries again. 我将更改的inline.js添加到我的项目文件夹中,它检查是否已加载jQuery,如果没有,则等待300毫秒,然后重试。 Patch here. 在这里打补丁。

--- django/contrib/admin/static/admin/js/inlines.js
+++ myproject/myproject/static/admin/js/inlines.js
@@ -15,7 +15,8 @@
  * Licensed under the New BSD License
  * See: http://www.opensource.org/licenses/bsd-license.php
  */
-(function($) {
+
+function start_inline($) {
     'use strict';
     $.fn.formset = function(opts) {
         var options = $.extend({}, $.fn.formset.defaults, opts);
@@ -292,4 +293,16 @@
             }
         });
     });
-})(django.jQuery);
+};
+
+function start_inline_loader() {
+    try {
+        start_inline(django.jQuery);
+
+    } catch(e) {
+        console.log('no jQuery, try again after 300 mc');
+        setTimeout( function() {start_inline_loader();}, 300)
+    }
+}
+
+start_inline_loader();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法读取未定义的属性'fn' - Uncaught TypeError: Cannot read property 'fn' of undefined 无法读取未定义/未捕获类型错误的属性“fn”:$(...).daterangepicker 不是函数 - Cannot read property 'fn' of undefined / Uncaught TypeError: $(...).daterangepicker is not a function 未捕获的TypeError:无法读取未定义的属性'fn',电子2,角6? - Uncaught TypeError: Cannot read property 'fn' of undefined, electron 2, angular 6? 未捕获的TypeError:无法读取未定义的属性“ add” - Uncaught TypeError: Cannot read property 'add' of undefined 把手TypeError:无法读取未定义的属性'fn' - Handlebars TypeError: Cannot read property 'fn' of undefined Jest - TypeError:无法读取未定义的属性“fn” - Jest - TypeError: Cannot read property 'fn' of undefined 加载FullCalendar> Uncaught TypeError:无法读取未定义的属性'push' - FullCalendar on loading > Uncaught TypeError: Cannot read property 'push' of undefined 未捕获的TypeError:无法读取builder.js中未定义的属性“model” - Uncaught TypeError: Cannot read property 'model' of undefined in builder.js Requirejs + Backbone Uncaught TypeError:无法读取未定义的属性“Model” - Requirejs + Backbone Uncaught TypeError: Cannot read property 'Model' of undefined Django jquery数据表:未捕获的TypeError:无法读取未定义的属性'length' - Django jquery datatable: Uncaught TypeError: Cannot read property 'length' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM