django 1.5管理内联

时间:2021-07-15 19:22:34

I have some models with a large number of inlines. Since not all are needed for every object I declared the inline model with extra = 0 so that a small add + appeared on the inline.

我有一些有大量内线的模型。由于不是所有对象都需要所有对象,所以我声明了带有额外= 0的内联模型,以便在内联上出现一个小的add +。

However, this seems to no longer work in django 1.5. If extra = 0 is set, the inline is no longer editable.

然而,这在django 1.5中似乎不再适用。如果额外的= 0被设置,内联将不再是可编辑的。

Is there a way to get the 1.4 behavior into 1.5?

是否有办法将1.4行为转换为1.5?

Example Code:

示例代码:

class ModelInline(admin.StackedInline):
    model = MyModel
    extra = 0

class OtherModelAdmin(admin.ModelAdmin)
    inlines = [ModelInline]

admin.site.register(OtherModel, OtherModelAdmin)

Edit (some screens):

编辑(一些屏幕):

Django 1.4: django 1.5管理内联

Django 1.4:

Django 1.5: django 1.5管理内联

Django 1.5:

(Hinzufügen == add)

(Hinzufugen = =添加)

3 个解决方案

#1


7  

This is already happen before.

这已经发生过了。

The new javascript made this impossible because the "Add Another" button 
was controlled by max_num, and ignored a value of 0.
The javascript ignored a value of 0 because max_num has a default value of 0, 
and all the code using it had taken to equating max_num = 0 with being "off". 
So you can't actually have a maximum of 0. It's not possible.

There is a patch create by Gabrial Hurley to restores desired behaviour without breaking anything else. This is 3years ago and I don't know if it still working for Django 1.5. Just try :)

加布里·赫尔利创建了一个补丁,可以在不破坏其他任何东西的情况下恢复所需的行为。这是3年前的事了,我不知道它是否还在为Django 1.5工作。试试:)

https://code.djangoproject.com/attachment/ticket/13023/13023_inlines_patch.diff

https://code.djangoproject.com/attachment/ticket/13023/13023_inlines_patch.diff

Here is the ticket for that same bug (3 years ago):

这是同样的错误(3年前)的罚单:

https://code.djangoproject.com/ticket/13023

https://code.djangoproject.com/ticket/13023

#2


2  

I ran into the same issue because I had the static admin content in a directory that was outside of django's install. Copying the Django 1.5 static content from django/contrib/admin/static/admin/js/ to STATIC_ROOT/admin/js fixed the issue.

我遇到了同样的问题,因为在django安装之外的目录中有静态管理内容。将Django 1.5静态内容从Django /悔过书/admin/静态/admin/js复制到STATIC_ROOT/admin/js,修复了这个问题。

#3


0  

the better solution would be to override the get_extra method of the inline itself. This works in Django 1.9, though i cannot say for earlier versions

更好的解决方案是重写内联本身的get_extra方法。这在Django 1.9中是有效的,但是我不能说在早期版本中是有效的

#1


7  

This is already happen before.

这已经发生过了。

The new javascript made this impossible because the "Add Another" button 
was controlled by max_num, and ignored a value of 0.
The javascript ignored a value of 0 because max_num has a default value of 0, 
and all the code using it had taken to equating max_num = 0 with being "off". 
So you can't actually have a maximum of 0. It's not possible.

There is a patch create by Gabrial Hurley to restores desired behaviour without breaking anything else. This is 3years ago and I don't know if it still working for Django 1.5. Just try :)

加布里·赫尔利创建了一个补丁,可以在不破坏其他任何东西的情况下恢复所需的行为。这是3年前的事了,我不知道它是否还在为Django 1.5工作。试试:)

https://code.djangoproject.com/attachment/ticket/13023/13023_inlines_patch.diff

https://code.djangoproject.com/attachment/ticket/13023/13023_inlines_patch.diff

Here is the ticket for that same bug (3 years ago):

这是同样的错误(3年前)的罚单:

https://code.djangoproject.com/ticket/13023

https://code.djangoproject.com/ticket/13023

#2


2  

I ran into the same issue because I had the static admin content in a directory that was outside of django's install. Copying the Django 1.5 static content from django/contrib/admin/static/admin/js/ to STATIC_ROOT/admin/js fixed the issue.

我遇到了同样的问题,因为在django安装之外的目录中有静态管理内容。将Django 1.5静态内容从Django /悔过书/admin/静态/admin/js复制到STATIC_ROOT/admin/js,修复了这个问题。

#3


0  

the better solution would be to override the get_extra method of the inline itself. This works in Django 1.9, though i cannot say for earlier versions

更好的解决方案是重写内联本身的get_extra方法。这在Django 1.9中是有效的,但是我不能说在早期版本中是有效的