Code

Opened 5 years ago

Closed 5 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: UI/UX:

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?


Attachments (0)

Change History (5)

comment:1 Changed 5 years ago by mrts

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to mrts
  • Patch needs improvement unset
  • Status changed from new to assigned

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

  • Version changed from 1.0 to SVN

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

  • Owner mrts deleted
  • Status changed from assigned to new

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

comment:4 Changed 5 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 5 years ago by Alex

  • Resolution set to duplicate
  • Status changed from new to closed

Marking as a dupe of #10761 as mrts notes.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.