Opened 18 months ago

Last modified 18 months ago

#21528 new Cleanup/optimization

improve Django Doc with an example for formfield_for_foreignkey accessing parent ID

Reported by: anonymous Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by aaugustin)

Please,
Could you add an example for formfield_for_foreignkey (
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey) showing how to access parent ID for filtering a foreignkey.

I saw on http://www.stereoplex.com/blog/filtering-dropdown-lists-in-the-django-admin

parent_id = request.META['PATH_INFO'].strip('/').split('/')[-1]

Clearly it's not ideal.

Thanks!

Change History (2)

comment:1 Changed 18 months ago by aaugustin

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Could you explain a bit more what you're trying to achieve?

To help you, we need something like: "here's my models definition, here's my admin definiton, at this URL ... I would like to..."

comment:2 Changed 18 months ago by timo

  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization

The request is a documentation additional as outlined in the blog post.

It would be nice if there were a cleaner way to achieve the filtering, but until then, I guess we can document this solution.

Note: See TracTickets for help on using tickets.
Back to Top