Ticket #12339: wordy_contenttype_update.diff

File wordy_contenttype_update.diff, 1.7 KB (added by Kenneth Arnold, 15 years ago)
  • django/contrib/contenttypes/management.py

     
    2828    # The presence of any remaining content types means the supplied app has an
    2929    # undefined model and can safely be removed, which cascades to also remove
    3030    # 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()
     31    if content_types:
     32        if kwargs.get('delete_stale', False):
     33            for ct in content_types:
     34                if verbosity >= 2:
     35                    print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model)
     36                ct.delete()
     37        else:
     38            print """
     39The following content types are stale:
     40%s
     41They may still be referenced by other models, so they are not being deleted.
     42To delete them, run:
     43>>> from django.contrib.contenttypes.management import update_all_contenttypes
     44>>> update_all_contenttypes(verbosity=2, delete_stale=False)
     45Verify that no other models reference those content types, then run:
     46>>> update_all_contenttypes(verbosity=2, delete_stale=True)
     47""" % ', '.join(['%s | %s' % (ct.app_label, ct.model) for ct in content_types])
    3548
    36 def update_all_contenttypes(verbosity=2):
     49def update_all_contenttypes(verbosity=2, **kwargs):
    3750    for app in get_apps():
    38         update_contenttypes(app, None, verbosity)
     51        update_contenttypes(app, None, verbosity, **kwargs)
    3952
    4053signals.post_syncdb.connect(update_contenttypes)
    4154
Back to Top