ImportError:无法导入名称update_all_contenttypes

Tro*_*roy 8 django django-1.8

我最近升级到Django 1.8.在以前的Django版本中,以下导入很好:

from django.contrib.contenttypes.management import update_all_contenttypes
Run Code Online (Sandbox Code Playgroud)

update_all_contenttypes似乎已经在Django 1.8中默默地删除了(它存在于1.7.7中).我在1.8发行说明中没有看到任何有关它被移除的内容......有谁知道现代替代品对于该功能是什么?

Tro*_*roy 9

目前还不清楚为什么在1.8中删除了这个功能,但现代替代品似乎只是重新发明了这个轮子:

from django.apps import apps
from django.contrib.contenttypes.management import update_contenttypes

def update_all_contenttypes(**kwargs):
    for app_config in apps.get_app_configs():
        update_contenttypes(app_config, **kwargs)
Run Code Online (Sandbox Code Playgroud)