#29138: Add ModelAdmin.autocomplete_fields support for ForeignKeys that use
to_field
-------------------------------+------------------------------------
     Reporter:  Jonathan Nye   |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  contrib.admin  |                  Version:  2.0
     Severity:  Normal         |               Resolution:
     Keywords:  autocomplete   |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------

Comment (by Johannes Hoppe):

 Hey Jonathan,

 well that sounds like the perfect opportunity to get into contributing to
 Django.

 Of course the is a contributing guide, but it long. I would recommend to
 read at least the section for new contributors.
 https://docs.djangoproject.com/en/dev/internals/contributing/

 Anyhow, this is how I would go about this:
 Write your test first. You should write a test, that exploits the bug you
 found and fails. You will need to add one at the end anyways, if you start
 with it actually fixing the issue will become a lot easier. You might want
 to add the test here
 `tests.admin_views.test_autocomplete_view.AutocompleteJsonViewTests`.

 Once that is out of the way there is this line in
 `django.contrib.admin.views.autocomplete.AutocompleteJsonView#get`. It
 returns a `JsonResponse` that includes the `obj.pk` at some point. What it
 should return is the value of the `to_field`.  This is where things might
 become tricky. Since there is only once view per model and probably
 multiple other models having foreign keys to that one, you will need to
 get the `to_field` from the relation or pass it as a GET parameter. In the
 latter case you should definitely validate the field to avoid leakage as
 Tim said earlier.

 Anyhow, just get started and let me know if you hit an obstacle and need
 help :)

 Best
 -Joe

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29138#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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.593bfb02fbba6c4474c5905b28e79d65%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to