﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16311	Option to limit list_filter to related_objects of instances of the list	Stanislas Guerra <stan@…>	nobody	"I know there are many snippets and blog entries to do that but it is a common use case to limit the FK/related model choices to the very objects displayed in the list and maybe the core team would consider to implement it directly in the Django admin. 

The +10 lines patch I provide allow you to limit the choices for a FK/M2M to the current object list by adding the attribute `RELATED_FIELD_filter_related_only=True` to your ModelAdmin.

By example :


{{{
class Order(models.Model):
    ...
    support = models.ForeignKey(Support)
    parutions = models.ManyToManyField(Parution, through='OrderParution', related_name='order')


class OrderAdmin(admin.ModelAdmin):
    ...
    list_filter = ('support', 'agency', 'parutions')
    parutions_filter_related_only=True
    support_filter_related_only=True


}}}


"	New feature	closed	contrib.admin	dev	Normal	fixed	admin, list_filter, limit_choices_to		Accepted	1	0	0	0	0	0
