Nick
unread,Aug 6, 2010, 5:56:37 PM8/6/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
I have an admin set up with three inlines. I would like to filter the
inline's editable options by a variable that is defined in a settings
file. I can over ride the actual admin pieces for each of the inlines
(they all have full admin screens of their own). But I can't seem to
get the standard def queryset(self, request): etc. over ride to work
for inlines. I have seen a little talk about how inlines require you
to create a new manager to filter the list of options.
Here is my inline admin code:
class CandidateInline(admin.TabularInline):
model = Candidate
fields = ['%s_vote' % (race_type)]
extra = 0
ordering = ('party', 'last_name')
## here is where the trouble is starting, I'd like to get rid of
everything that isn't status 1 ###
def queryset(self, request):
qs = super(CandidateInline, self).queryset(request)
return qs.filter(status="1").exclude(party="Independent")
and here is the primary admin model that this inline is attached to:
class RaceAdmin(admin.ModelAdmin):
inlines = [
CandidateInline,
PrecinctInline,
]
form = RaceForm
fieldsets = (
('General Race Information', {
'fields': ('name', 'office_name', 'type', 'county',
'general_winner')
}),
('Partisan Race Outcomes (Runoff)', {
'classes': ('collapse',),
'fields': ('runoff_winner_d', 'runoff_winner_r',
'primary_advance_d', 'primary_advance_r'),
}),
('Non Partisan Race Outcomes (Runoff)', {
'classes': ('collapse',),
'fields': ('runoff_winner_np',)
}),
)
list_display = ('name', 'type', 'county', )
list_filter = ('type', 'office_name', 'county')
ordering = ['name']
# redefine the queryset to get rid of finals
def queryset(self, request):
qs = super(RaceAdmin, self).queryset(request)
return qs.filter(type="2")