Skip to content

Instantly share code, notes, and snippets.

@bmihelac
Created June 28, 2012 09:07
Show Gist options
  • Save bmihelac/3010093 to your computer and use it in GitHub Desktop.
Save bmihelac/3010093 to your computer and use it in GitHub Desktop.
Refresh django ContentType names
# changing verbose name of model does not change ContentType name
# this script will loop through all ContentType objects and refresh names
# optional activate translation
from django.utils import translation
translation.activate('en')
from django.contrib.contenttypes.models import ContentType
content_types = ContentType.objects.all()
for ct in content_types:
model = ct.model_class()
if model:
ct.name = model._meta.verbose_name
ct.save()
@benwhalley
Copy link

AttributeError: can't set attribute in Django 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment