def rename_content_types(apps, schema_editor):
    """Rename old content types if necessary."""
    ContentType = apps.get_model('contenttypes', 'ContentType')
    for ct in ContentType.objects.filter(app_label='modoboa_admin'):
        try:
            old_ct = ContentType.objects.get(app_label='admin', model=ct.model)
        except ContentType.DoesNotExist:
            continue
        old_ct.app_label = 'modoboa_admin'
        ct.delete()
        old_ct.save()
