#34566: ModelAdmin get_field_queryset uses related admin ordering, but not 
related
admin querysets.
-------------------------------+------------------------------------
     Reporter:  Mike J         |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  contrib.admin  |                  Version:  4.2
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  1              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------
Changes (by Natalia Bidart):

 * stage:  Unreviewed => Accepted


Comment:

 I'm tentatively accepting the bug because I think that the exception
 raising is an issue. The proposed fix in the
 [https://github.com/django/django/pull/16859 associated PR] (which needs
 tests and docs) does make sense to me but I would definitely seek for
 opinions from more experienced contributors.

 I believe that a way to solve this in the user code would be to change the
 `ReportAdmin` to include `formfield_for_foreignkey` like this:

 {{{
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         formfield = super().formfield_for_foreignkey(db_field, request,
 **kwargs)
         if db_field.name == "owner":
             related_admin =
 self.admin_site._registry.get(db_field.remote_field.model)
             formfield.queryset = related_admin.get_queryset(request)
         return formfield
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34566#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/0107018820eb62a2-401ad4cb-726e-4995-a5a8-619917dc8a95-000000%40eu-central-1.amazonses.com.

Reply via email to