#33375: Admin changelist_formset does not use the Admin queryset
----------------------------------+--------------------------------------
Reporter: François Freitag | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Carlton Gibson):
* status: new => closed
* resolution: => wontfix
Comment:
Thanks for the update François.
> `[{'id': ['Select a valid choice. That choice is not one of the
available choices.']}, {}]`
So just looking at that, you have a `ModelChoiceField` with the wrong
QuerySet, and sure enough...
{{{
(Pdb) form.fields
{'deleted': <django.forms.fields.BooleanField object at 0x104a136a0>,
'id': <django.forms.models.ModelChoiceField object at 0x104a13a90>}
(Pdb) form.fields['id'].queryset
<QuerySet [<SoftDeletable: SoftDeletable object (2)>]>
}}}
Why? Because in
[https://github.com/django/django/blob/33401cba9317de2487c31ffdd1a5a51ecfbc0248/django/forms/models.py#L859-L862
BaseModelFormSet.add_fields()] we add a just such a field using the
default manager.
I suspect that's untouchable, and just a limitation of the _soft delete_
approach.
I'd look at overriding
[https://docs.djangoproject.com/en/4.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_changelist_form
ModelAdmin.get_changelist_form] (or maybe
ModelAdmin.get_changelist_formset) to provide the base form class
declaring the `id` `ModelChoiceField` with the correct (for your case)
QuerySet.
I'm going to mark as wontfix. If you come up with a suggestion, happy to
take a look (but... :)
--
Ticket URL: <https://code.djangoproject.com/ticket/33375#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/073.a0b4abd5954e15d98371c94ca3f993a2%40djangoproject.com.