ImportError: cannot import name update_all_contenttypes

前端 未结 2 1089
执念已碎
执念已碎 2020-12-20 17:20

I upgraded recently to Django 1.8. In previous versions of Django, the following import was fine:

from django.contrib.contenttypes.management import update_         


        
2条回答
  •  醉梦人生
    2020-12-20 17:46

    It's unclear why that function was removed in 1.8, but it appears that the modern replacement is to just re-invent that wheel:

    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)
    

提交回复
热议问题