Skip to content

Instantly share code, notes, and snippets.

@marcelor
Last active December 28, 2015 09:29
Show Gist options
  • Save marcelor/7479105 to your computer and use it in GitHub Desktop.
Save marcelor/7479105 to your computer and use it in GitHub Desktop.
Signal to update the column name in the Django's content types table when the verbose_name of a model is added, modified or deleted. Original code: http://stackoverflow.com/questions/6847020/when-verbose-name-changes-how-do-i-auto-update-a-models-contenttype
from django.contrib.contenttypes.models import ContentType
from django.utils.functional import Promise
from south.signals import post_migrate
def update_contenttypes_names(**kwargs):
for c in ContentType.objects.all():
cl = c.model_class()
if cl:
new_name = cl._meta.verbose_name
if c.name != new_name:
print u"Updating ContentType's name: '%s' -> '%s'" % (c.name, new_name)
c.name = new_name
c.save()
post_migrate.connect(update_contenttypes_names, dispatch_uid="update_contenttypes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment