Opened 11 years ago

Closed 11 years ago

#11019 closed (duplicate)

Admin inlines queryset

Reported by: pcicman Owned by:
Component: contrib.admin Version: master
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


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.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 Changed 11 years ago by mrts

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 Changed 11 years ago by pcicman

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.instance}) # instead of qs = self.model._default_manager
    # and then pass it to super the same way like now

comment:3 Changed 11 years ago by mrts

Owner: mrts deleted
Status: assignednew

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

comment:4 Changed 11 years ago by mrts

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 Changed 11 years ago by Alex Gaynor

Resolution: duplicate
Status: newclosed

Marking as a dupe of #10761 as mrts notes.

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