Ticket #1856: djangocontenttypeandperms.diff

File djangocontenttypeandperms.diff, 1.6 KB (added by mattimustang@…, 18 years ago)

content types and perms creation patch

  • django/contrib/contenttypes/management.py

     
     1"""
     2Creates content types for all installed models.
     3"""
     4
     5from django.dispatch import dispatcher
     6from django.db.models import get_models, signals
     7
     8def create_contenttypes(app, created_models):
     9    from django.contrib.contenttypes.models import ContentType
     10    app_models = get_models(app)
     11    if not app_models:
     12        return
     13    for klass in app_models:
     14        opts = klass._meta
     15        try:
     16            ContentType.objects.get(app_label=opts.app_label,
     17                model=opts.object_name.lower())
     18        except ContentType.DoesNotExist:
     19            ct = ContentType(name=str(opts.verbose_name),
     20                app_label=opts.app_label, model=opts.object_name.lower())
     21            ct.save()
     22            print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
     23
     24dispatcher.connect(create_contenttypes, signal=signals.post_syncdb)
  • django/contrib/auth/management.py

     
    2323    if not app_models:
    2424        return
    2525    for klass in app_models:
    26         if not klass._meta.admin:
    27             continue
    2826        ctype = ContentType.objects.get_for_model(klass)
    2927        for codename, name in _get_all_permissions(klass._meta):
    3028            try:
Back to Top