Changeset 4328
- Timestamp:
- 01/15/07 18:09:53 (2 years ago)
- Files:
-
- django/branches/newforms-admin/django/contrib/admin/options.py (modified) (2 diffs)
- django/branches/newforms-admin/django/contrib/admin/templatetags/admin_list.py (modified) (3 diffs)
- django/branches/newforms-admin/django/contrib/admin/views/main.py (modified) (4 diffs)
- django/branches/newforms-admin/django/db/models/base.py (modified) (1 diff)
- django/branches/newforms-admin/django/db/models/options.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/newforms-admin/django/contrib/admin/options.py
r4326 r4328 33 33 class ModelAdmin(object): 34 34 "Encapsulates all admin options and functionality for a given model." 35 36 list_display = ('__str__',) 37 35 38 def __init__(self, model): 36 39 self.model = model … … 267 270 raise PermissionDenied 268 271 try: 269 cl = ChangeList(request, self.model )272 cl = ChangeList(request, self.model, self.list_display) 270 273 except IncorrectLookupParameters: 271 274 # Wacky lookup parameters were given, so redirect to the main django/branches/newforms-admin/django/contrib/admin/templatetags/admin_list.py
r4309 r4328 70 70 lookup_opts = cl.lookup_opts 71 71 72 for i, field_name in enumerate( lookup_opts.admin.list_display):72 for i, field_name in enumerate(cl.list_display): 73 73 try: 74 74 f = lookup_opts.get_field(field_name) … … 109 109 first = True 110 110 pk = cl.lookup_opts.pk.attname 111 for field_name in cl.l ookup_opts.admin.list_display:111 for field_name in cl.list_display: 112 112 row_class = '' 113 113 try: … … 173 173 result_repr = ' ' 174 174 # If list_display_links not defined, add the link tag to the first field 175 if (first and not cl.lookup_opts.admin.list_display_links) or field_name in cl.lookup_opts.admin.list_display_links: 175 if (first and not cl.lookup_opts.admin.list_display_links) or field_name in cl.lookup_opts.admin.list_display_links: 176 176 table_tag = {True:'th', False:'td'}[first] 177 177 first = False django/branches/newforms-admin/django/contrib/admin/views/main.py
r4326 r4328 82 82 if not model._meta.admin: 83 83 raise Http404("This object has no admin interface.") 84 mav = ModelAdmin(model)84 mav = model._meta.ModelAdmin(model) 85 85 return mav(request, rest_of_url) 86 86 model_admin_view = staff_member_required(never_cache(model_admin_view)) … … 293 293 294 294 class ChangeList(object): 295 def __init__(self, request, model ):295 def __init__(self, request, model, list_display): 296 296 self.model = model 297 297 self.opts = model._meta 298 298 self.lookup_opts = self.opts 299 299 self.manager = self.opts.admin.manager 300 self.list_display = list_display 300 301 301 302 # Get search parameters from the query string. … … 405 406 try: 406 407 try: 407 f = lookup_opts.get_field( lookup_opts.admin.list_display[int(params[ORDER_VAR])])408 f = lookup_opts.get_field(self.list_display[int(params[ORDER_VAR])]) 408 409 except models.FieldDoesNotExist: 409 410 pass … … 432 433 qs = qs.select_related() 433 434 else: 434 for field_name in self.l ookup_opts.admin.list_display:435 for field_name in self.list_display: 435 436 try: 436 437 f = self.lookup_opts.get_field(field_name) django/branches/newforms-admin/django/db/models/base.py
r4265 r4328 131 131 if name == 'Admin': 132 132 assert type(value) == types.ClassType, "%r attribute of %s model must be a class, not a %s object" % (name, cls.__name__, type(value)) 133 from django.contrib.admin.options import ModelAdmin 134 # Dynamically create a new ModelAdmin class, which is a subclass 135 # of both ModelAdmin and the 'class Admin' on this model. The 136 # resulting class is same as if the 'class Admin' were a subclass 137 # of ModelAdmin. 138 cls._meta.ModelAdmin = type('ModelAdmin', (value, ModelAdmin), {}) 139 # This AdminOptions stuff is legacy and will eventually be removed. 133 140 value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')])) 134 if hasattr(value, 'contribute_to_class'): 141 value.contribute_to_class(cls, name) 142 elif hasattr(value, 'contribute_to_class'): 135 143 value.contribute_to_class(cls, name) 136 144 else: django/branches/newforms-admin/django/db/models/options.py
r4265 r4328 88 88 def __repr__(self): 89 89 return '<Options for %s>' % self.object_name 90 90 91 91 def __str__(self): 92 92 return "%s.%s" % (self.app_label, self.module_name) 93 93 94 94 def get_field(self, name, many_to_many=True): 95 95 "Returns the requested field by name. Raises FieldDoesNotExist on error."
