Changeset 8063
- Timestamp:
- 07/23/08 13:58:06 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/admin/sites.py
r8006 r8063 2 2 from django.contrib.admin import ModelAdmin 3 3 from django.contrib.auth import authenticate, login 4 from django.core.exceptions import ImproperlyConfigured 4 5 from django.db.models.base import ModelBase 5 6 from django.shortcuts import render_to_response … … 67 68 If a model is already registered, this will raise AlreadyRegistered. 68 69 """ 69 do_validate = admin_class and settings.DEBUG 70 if do_validate: 71 # don't import the humongous validation code unless required 70 # Don't import the humongous validation code unless required 71 if admin_class and settings.DEBUG: 72 72 from django.contrib.admin.validation import validate 73 admin_class = admin_class or ModelAdmin 74 # TODO: Handle options 73 else: 74 validate = lambda model, adminclass: None 75 76 if not admin_class: 77 admin_class = ModelAdmin 75 78 if isinstance(model_or_iterable, ModelBase): 76 79 model_or_iterable = [model_or_iterable] … … 78 81 if model in self._registry: 79 82 raise AlreadyRegistered('The model %s is already registered' % model.__name__) 80 if do_validate: 81 validate(admin_class, model) 83 84 # If we got **options then dynamically construct a subclass of 85 # admin_class with those **options. 86 if options: 87 # For reasons I don't quite understand, without a __module__ 88 # the created class appears to "live" in the wrong place, 89 # which causes issues later on. 90 options['__module__'] = __name__ 91 admin_class = type("%sAdmin" % model.__name__, (admin_class,), options) 92 93 # Validate (which might be a no-op) 94 validate(admin_class, model) 95 96 # Instantiate the admin class to save in the registry 82 97 self._registry[model] = admin_class(model, self) 83 98
