Ticket #4326: django_new_admin_2_bug_fixed.patch

File django_new_admin_2_bug_fixed.patch, 2.5 KB (added by yi.codeplayer at gmail dot com, 17 years ago)

The Patch.

  • django/contrib/admin/sites.py

     
    22from django.contrib.admin import ModelAdmin
    33from django.contrib.auth import authenticate, login
    44from django.db.models import Model
     5from django.db.models.base import ModelBase
    56from django.shortcuts import render_to_response
    67from django.utils.text import capfirst
    78from django.utils.translation import gettext_lazy
     9from django.utils.datastructures import SortedDict
    810import base64
    911import cPickle as pickle
    1012import datetime
     
    6971        """
    7072        admin_class = admin_class or ModelAdmin
    7173        # TODO: Handle options
    72         if issubclass(model_or_iterable, Model):
     74        if isinstance(model_or_iterable, ModelBase) and issubclass(model_or_iterable, Model):
    7375            model_or_iterable = [model_or_iterable]
    7476        for model in model_or_iterable:
    7577            if model in self._registry:
     
    234236        Displays the main admin index page, which lists all of the installed
    235237        apps that have been registered in this site.
    236238        """
    237         app_list = []
     239        apps = SortedDict()
    238240        user = request.user
    239241        for model, model_admin in self._registry.items():
    240242            app_label = model._meta.app_label
     
    254256                        'admin_url': '%s/%s/' % (app_label, model.__name__.lower()),
    255257                        'perms': perms,
    256258                    }
    257                     app_list.append({
    258                         'name': app_label.title(),
    259                         'has_module_perms': has_module_perms,
    260                         'models': [model_dict],
    261                     })
     259                    if app_label in apps:
     260                        apps[app_label]['models'].append(model_dict)
     261                    else:
     262                        apps[app_label] = {
     263                            'name': app_label.title(),
     264                            # I found that this isn't used in template.
     265                            #'has_module_perms': has_module_perms,
     266                            'models': [model_dict],
     267                        }
    262268        return render_to_response('admin/index.html', {
    263269            'title': _('Site administration'),
    264             'app_list': app_list,
     270            'app_list': apps.values(),
    265271        }, context_instance=template.RequestContext(request))
    266272
    267273# This global object represents the default admin site, for the common case.
Back to Top