Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

django - ImportError: cannot import name update_all_contenttypes

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

from django.contrib.contenttypes.management import update_all_contenttypes

But update_all_contenttypes appears to have been silently removed in Django 1.8 (it was there in 1.7.7). I'm not seeing anything in the 1.8 release notes about its removal... Does anyone know what the modern replacement is for that function?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...