Opened 16 years ago

Closed 16 years ago

#8319 closed (wontfix)

limit_choices_to does not limit choices on inlined fields with intermediate tables

Reported by: TrevorFSmith Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Limiting the choices for a tabular inlined member with an intermediate class does not limit the choices. In the example below, the select elements in the admin interface include every story, not just stories which have a start date in the past.

For inlined tables where there are thousands of records this can bloat admin page sizes beyond usability.

In models.py:

class PageContent(models.Model):
	stories = models.ManyToManyField('Story', limit_choices_to={'start_date__lte': datetime.now()}, through='PageContentStoryMembership')

class PageContentStoryMembership(models.Model):
	page_content = models.ForeignKey(PageContent)
	story = models.ForeignKey('Story')
	weight = models.IntegerField(null=False, default=0)

In admin.py:

class PageContentStoryMembershipInline(admin.TabularInline):
	model = PageContentStoryMembership

class PageContentAdmin(admin.ModelAdmin):
	inlines = [PageContentStoryMembershipInline]

Change History (6)

comment:1 by Russell Keith-Magee, 16 years ago

(In [8365]) Refs #8319 -- Added documentation note on the limitations of limit_choices_to.

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: wontfix
Status: newclosed

limit_choices_to has never had an effect on inline edit objects; I've updated the documentation to reflect this fact.

However, the admin does provide an alternative - if you want to limit choices on an inline formset, override the queryset() method on the InlineModelAdmin to include only those related objects that you want to display.

in reply to:  2 comment:3 by TrevorFSmith, 16 years ago

Resolution: wontfix
Status: closedreopened

Replying to russellm:

limit_choices_to has never had an effect on inline edit objects; I've updated the documentation to reflect this fact.

Just because it never worked does not mean it shouldn't work.

However, the admin does provide an alternative - if you want to limit choices on an inline formset, override the queryset() method on the InlineModelAdmin to include only those related objects that you want to display.

I tried this before filing the but and it also does not work for ManyToManyFields with intermediate tables, since the queryset handled in that function is for the intermediate table records, not the referenced table.

comment:4 by TrevorFSmith, 16 years ago

Actually, because queryset() is defined in ModelAdmin and not BaseModelAdmin, it cannot be overidden by InlineModelAdmin

comment:5 by Piotr Lewandowski <django@…>, 16 years ago

Component: UncategorizedAdmin interface

comment:6 by Jacob, 16 years ago

Resolution: wontfix
Status: reopenedclosed

Please don't reopen tickets closed by a committer. The correct way to revisit issues is to take it up on django-dev.

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