--
Ticket URL: <https://code.djangoproject.com/ticket/27157>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Can you give some example code that causes this error? `AdminForm` isn't a
public API, and I'm not sure if you're calling it directly or triggering
the problem some other way.
--
Ticket URL: <https://code.djangoproject.com/ticket/27157#comment:1>
Comment (by tpazderka):
This is just a stub as our class is not based on `BaseFormset` but rather
reimplements its methods...
I am not sure if this is sufficient. If not, I will try to write more
complete example.
{{{
#!python
class ContactFormset(BaseFormset):
@property
def forms(self):
"""
Iterates through forms and returns them wrapped by `AdminForm`.
"""
for form, datatype in zip(self._forms, self.get_types()):
yield AdminForm(form, (self.get_fieldset(datatype), ), {},
self.get_readonly_fields(datatype))
}}}
The last line has to be replaced by:
{{{
#!python
yield AdminForm(form, (self.get_fieldset(datatype), ), {},
self.get_readonly_fields(datatype), model_admin=ModelAdmin(MojeidUser,
AdminSite))
}}}
in order to work in django 1.9 and later.
--
Ticket URL: <https://code.djangoproject.com/ticket/27157#comment:2>
* stage: Unreviewed => Accepted
Comment:
I guess, for example, we need to account for `model_admin=None` in a place
like
[https://github.com/django/django/blob/d8ef5b0e6501692b8b767ebccddc936f496d77e8/django/contrib/admin/helpers.py#L185
AdminReadonlyField]. It's not so clear to me why `model_admin` is an
optional argument (see bcd9482a2019158f4580c24cd50ee8bfae9b2739), perhaps
for backwards compatibility. A better resolution might be a deprecation
path toward making those arguments required unless there's argument
against it. In your case, if you using that formset for the admin, then a
possibility would be to declare the formset in
`ModelAdmin.get_changelist_formset()` so you can access to the
`ModelAdmin` class (`self`).
--
Ticket URL: <https://code.djangoproject.com/ticket/27157#comment:3>