Ticket #5177: ctremove.diff

File ctremove.diff, 2.1 KB (added by Rob Hudson <treborhudson@…>, 17 years ago)

First attempt at a patch for this. This is a diff from git so this may need tweaking...

  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index c690980..e741f59 100644
    a b answer newbie questions, and generally made Django that much better:  
    289289    ymasuda@ethercube.com
    290290    Jarek Zgoda <jarek.zgoda@gmail.com>
    291291    Cheng Zhang
     292    Rob Hudson <http://rob.cogit8.org/>
    292293
    293294A big THANK YOU goes to:
    294295
  • django/contrib/contenttypes/management.py

    diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
    index cb52e08..663628b 100644
    a b  
    22Creates content types for all installed models.
    33"""
    44
     5from django.contrib.contenttypes.models import ContentType
    56from django.dispatch import dispatcher
    67from django.db.models import get_apps, get_models, signals
    78from django.utils.encoding import smart_unicode
    89
    910def create_contenttypes(app, created_models, verbosity=2):
    10     from django.contrib.contenttypes.models import ContentType
    1111    ContentType.objects.clear_cache()
     12    content_types = list(ContentType.objects.filter(app_label=app.__name__.split('.')[-2]))
    1213    app_models = get_models(app)
    1314    if not app_models:
    1415        return
    1516    for klass in app_models:
    1617        opts = klass._meta
    1718        try:
    18             ContentType.objects.get(app_label=opts.app_label,
    19                 model=opts.object_name.lower())
     19            ct = ContentType.objects.get(app_label=opts.app_label,
     20                                         model=opts.object_name.lower())
     21            content_types.remove(ct)
    2022        except ContentType.DoesNotExist:
    2123            ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
    2224                app_label=opts.app_label, model=opts.object_name.lower())
    2325            ct.save()
    2426            if verbosity >= 2:
    2527                print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
     28    # any remaining content types don't have a matching model and are removed
     29    for ct in content_types:
     30        if verbosity >= 2:
     31            print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model)
     32        ct.delete()
    2633
    2734def create_all_contenttypes(verbosity=2):
    2835    for app in get_apps():
Back to Top