Opened 15 years ago

Closed 15 years ago

#11019 closed (duplicate)

Admin inlines queryset

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

Description

I think the way how admin inlines are accessed is wrong.
BaseInlineFormSet does not cares about queryset defined in admin istance.

It uses default manager instead, and some filtering on it (filtering is of course right):

self.model._default_manager.filter(**{self.fk.name: self.instance})

Is there any reason why it not uses filtering on queryset returned by queryset method from admin instance instead of default manager? Or is this just a bug?


Change History (5)

comment:1 by mrts, 15 years ago

Owner: changed from nobody to mrts
Status: newassigned

Essentially, this is a duplicate of #10761. Won't mark it as such as other people might have different view of the subject.

comment:2 by pcicman, 15 years ago

Version: 1.0SVN

I don't think that this is a duplicate of #10761, but extensions described in #10761 are nice.

Inline queryset can be quicky fixed, in get_formset method or inline_factory. inline_factory is assigning fk to BaseInlineFormSet class, queryset can be assigned the same way in get_formset (i think is better to assign it in get_formset), so:

FormSet.queryset = self.queryset(request)

queryset can then be raded out in constructor of BaseInlineFormSet:

def __init__(self, ...)
    ....
    qs = self.queryset.filter(**{self.fk.name: self.instance}) # instead of qs = self.model._default_manager
    # and then pass it to super the same way like now

comment:3 by mrts, 15 years ago

Owner: mrts removed
Status: assignednew

(Didn't intend to assign this to myself).

comment:4 by mrts, 15 years ago

It is essentially a duplicate, not directly. The point of #10761 is that all admin querysets (including for inlines) should get an extensible, consistent and thought out overhaul.

comment:5 by Alex Gaynor, 15 years ago

Resolution: duplicate
Status: newclosed

Marking as a dupe of #10761 as mrts notes.

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