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")
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.