class MyModelAdmin(admin.ModelAdmin):
inlines = [MyInline]
}}}
'''admin.E104''' will be added to the error stack because its not a
subclass (ugh) of BaseModelAdmin.
changing to:
{{{
class MyInline(BaseModelAdmin): pass
}}}
will throw:
{{{
AttributeError: type object 'MyInline' has no attribute 'model'
}}}
because its not until `ModelAdmin` or `InlineModelAdmin` that the
attribute is set (in `__init__` for `ModelAdmin`, as a class attribute for
`InlineModelAdmin`)
Encountered on 1.9, but looks to be the same in master.
--
Ticket URL: <https://code.djangoproject.com/ticket/26816>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26816#comment:1>
Comment (by kezabelle):
Additional addendum:
{{{
class MyInline(BaseModelAdmin):
model = MyModel
}}}
will also fail it seems, because `BaseModelAdmin` doesn't have the same
`__init__` argspec as `InlineModelAdmin`:
{{{
TypeError: __init__() takes 1 positional argument but 3 were given
}}}
I suppose the simplest fix is to check the inline is a subclass of
`InlineModelAdmin`.
--
Ticket URL: <https://code.djangoproject.com/ticket/26816#comment:2>
* owner: nobody => berkerpeksag
* status: new => assigned
* has_patch: 0 => 1
* cc: berker.peksag@… (added)
Comment:
For future reference, here is the full traceback when `BaseModelAdmin` is
used as a base class (see comment 2 for full example):
{{{
Unhandled exception in thread started by <function wrapper at 0x2f98668>
Traceback (most recent call last):
File "/home/berker/projects/django/django/utils/autoreload.py", line
226, in wrapper
fn(*args, **kwargs)
File
"/home/berker/projects/django/django/core/management/commands/runserver.py",
line 113, in inner_run
autoreload.raise_last_exception()
File "/home/berker/projects/django/django/utils/autoreload.py", line
249, in raise_last_exception
six.reraise(*_exception)
File "/home/berker/projects/django/django/utils/autoreload.py", line
226, in wrapper
fn(*args, **kwargs)
File "/home/berker/projects/django/django/__init__.py", line 27, in
setup
apps.populate(settings.INSTALLED_APPS)
File "/home/berker/projects/django/django/apps/registry.py", line 115,
in populate
app_config.ready()
File "/home/berker/projects/django/django/contrib/admin/apps.py", line
23, in ready
self.module.autodiscover()
File "/home/berker/projects/django/django/contrib/admin/__init__.py",
line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/berker/projects/django/django/utils/module_loading.py", line
50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in
import_module
__import__(name)
File "/home/berker/projects/testdjango/core/admin.py", line 38, in
<module>
site.register(SlugModel, SlugAdmin)
File "/home/berker/projects/django/django/contrib/admin/sites.py", line
110, in register
system_check_errors.extend(admin_obj.check())
File "/home/berker/projects/django/django/contrib/admin/options.py",
line 117, in check
return self.checks_class().check(self, **kwargs)
File "/home/berker/projects/django/django/contrib/admin/checks.py", line
519, in check
errors.extend(self._check_inlines(admin_obj))
File "/home/berker/projects/django/django/contrib/admin/checks.py", line
557, in _check_inlines
for index, item in enumerate(obj.inlines)
File "/home/berker/projects/django/django/contrib/admin/checks.py", line
585, in _check_inlines_item
return inline(model, obj.admin_site).check()
TypeError: __init__() takes exactly 1 argument (3 given)
}}}
[https://github.com/django/django/pull/7149 PR]. `test_not_model_admin`
and `test_missing_model_field` in `tests/modeladmin/tests.py` already
tested the behaviors demonstrated by kezabelle.
--
Ticket URL: <https://code.djangoproject.com/ticket/26816#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"426bca002c7902ceae230e0ce08a76dd6b6d3a06" 426bca00]:
{{{
#!CommitTicketReference repository=""
revision="426bca002c7902ceae230e0ce08a76dd6b6d3a06"
Fixed #26816 -- Corrected an admin check to require inlines to subclass
InlineModelAdmin.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26816#comment:4>