29 | | # undefined model and can safely be removed, which cascades to also remove |
30 | | # related permissions. |
31 | | for ct in content_types: |
32 | | if verbosity >= 2: |
33 | | print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model) |
34 | | ct.delete() |
| 29 | # undefined model. It may not be safe to remove it, however, if other |
| 30 | # models reference it by foreign key. |
| 31 | if content_types: |
| 32 | if kwargs.get('interactive', False): |
| 33 | content_type_display = ', '.join(['%s | %s' % (ct.app_label, ct.model) for ct in content_types]) |
| 34 | ok_to_delete = raw_input("""The following content types are stale: |
| 35 | %s |
| 36 | Would you like to delete them? If another object references one of these by a foreign key, it will also get deleted, which may not be what you want. |
| 37 | If you're unsure, answer 'no'. |
36 | | def update_all_contenttypes(verbosity=2): |
| 39 | Type 'yes' to continue, or 'no' to cancel: """ % content_type_display) |
| 40 | else: |
| 41 | ok_to_delete = False |
| 42 | |
| 43 | if ok_to_delete == 'yes': |
| 44 | for ct in content_types: |
| 45 | if verbosity >= 2: |
| 46 | print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model) |
| 47 | ct.delete() |
| 48 | else: |
| 49 | if verbosity >= 2: |
| 50 | print """ |
| 51 | Stale content types remain. To clean them up, call ct.delete on each of the |
| 52 | following objects after verifying that they are not referenced anywhere: |
| 53 | |
| 54 | >>> from django.contrib.contenttypes.models import ContentType""" |
| 55 | for ct in content_types: |
| 56 | print ">>> ct = ContentType.objects.get(app_label=%r, model=%r)" % (ct.app_label, ct.model) |
| 57 | |
| 58 | |
| 59 | def update_all_contenttypes(verbosity=2, **kwargs): |