Ticket #9749: patch_django_9749.20090111.diff
File patch_django_9749.20090111.diff, 5.3 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/validation.py
5 5 6 6 from django.core.exceptions import ImproperlyConfigured 7 7 from django.db import models 8 8 from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model 9 9 from django.contrib.admin.options import flatten_fieldsets, BaseModelAdmin 10 10 from django.contrib.admin.options import HORIZONTAL, VERTICAL 11 from django.contrib.admin.views.main import ChangeList 11 12 12 13 __all__ = ['validate'] 13 14 … … 138 144 raise ImproperlyConfigured("'%s.formset' does not inherit from " 139 145 "BaseModelFormSet." % cls.__name__) 140 146 147 # exclude 148 if hasattr(cls, 'exclude') and cls.exclude: 149 fk_name = _get_foreign_key(parent_model, cls.model).name 150 if fk_name in cls.exclude: 151 raise ImproperlyConfigured("'%s.exclude' should not contain " 152 "'%s' key because it's used in " 153 "%s." % (cls.__name__, fk_name, parent.__name__)) 154 141 155 def validate_base(cls, model): 142 156 opts = model._meta 143 157 -
django/contrib/admin/options.py
153 153 154 154 class ModelAdmin(BaseModelAdmin): 155 155 "Encapsulates all admin options and functionality for a given model." 156 # Avoid circular import of ChangeList 157 from django.contrib.admin.views.main import ChangeList 158 156 159 __metaclass__ = forms.MediaDefiningClass 157 160 158 161 list_display = ('__str__',) … … 166 169 save_on_top = False 167 170 ordering = None 168 171 inlines = [] 172 changelist_class = ChangeList 169 173 170 174 # Custom templates (designed to be over-ridden in subclasses) 171 175 change_form_template = None … … 620 624 621 625 def changelist_view(self, request, extra_context=None): 622 626 "The 'change list' admin view for this model." 623 from django.contrib.admin.views.main import ChangeList, ERROR_FLAG624 627 opts = self.model._meta 625 628 app_label = opts.app_label 626 629 if not self.has_change_permission(request, None): 627 630 raise PermissionDenied 628 631 try: 629 cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,632 cl = self.changelist_class(request, self.model, self.list_display, self.list_display_links, self.list_filter, 630 633 self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self) 631 634 except IncorrectLookupParameters: 632 635 # Wacky lookup parameters were given, so redirect to the main … … 634 637 # parameter via the query string. If wacky parameters were given and 635 638 # the 'invalid=1' parameter was already in the query string, something 636 639 # is screwed up with the database, so display an error page. 640 from django.contrib.admin.views.main import ERROR_FLAG 637 641 if ERROR_FLAG in request.GET.keys(): 638 642 return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) 639 643 return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1') -
tests/regressiontests/modeladmin/models.py
912 912 ... inlines = [ValidationTestInline] 913 913 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 914 914 915 # changelist_class 916 917 >>> class ValidationTestModelAdmin(ModelAdmin): 918 ... changelist_class = object 919 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 920 Traceback (most recent call last): 921 ... 922 ImproperlyConfigured: 'ValidationTestModelAdmin.changelist_class' does not inherit from admin.views.main.ChangeList. 923 924 >>> from django.contrib.admin.views.main import ChangeList 925 >>> class ValidationTestChangeList(ChangeList): 926 ... def url_for_result(self, result): 927 ... return "custom/%s/" % quote(getattr(result, self.pk_attname)) 928 >>> class ValidationTestModelAdmin(ModelAdmin): 929 ... changelist_class = ValidationTestChangeList 930 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 931 915 932 """ 916 933 } -
docs/ref/contrib/admin.txt
77 77 class AuthorAdmin(admin.ModelAdmin): 78 78 date_hierarchy = 'pub_date' 79 79 80 ``changelist_class`` 81 ~~~~~~~~~~~~~~~~~~ 82 83 Set ``changelist_class`` to a class which inherits from 84 ``admin.views.main.ChangeList``, and the change list page will use this class 85 to render the list. 86 87 Example:: 88 89 from django.contrib.admin.views.main import ChangeList 90 91 class CustomChangeList(ChangeList): 92 def url_for_result(self, result): 93 return "custom/%s/" % quote(getattr(result, self.pk_attname)) 94 95 class AuthorAdmin(admin.ModelAdmin): 96 date_hierarchy = 'pub_date' 97 changelist_class = CustomChangeList 98 99 80 100 ``date_hierarchy`` 81 101 ~~~~~~~~~~~~~~~~~~ 82 102