Newforms-admin : a better hook for admin pages (Adrian Holovaty)

Skip to first unread message


Apr 10, 2007, 6:51:57 AM4/10/07
to Django developers
Hi guys,

I have submitted a patch :
and before you refuse it, I just want to explain why imo it is
useful ;-) !

At the moment, a ForeignKey (or any related field) is displayed in the
admin with a list of all the items of the database. That may be
powerful, but it is often too much.
I can want the list of categories which belong to a specific super-
category, a list of ressources which are online (eg. status == 1),
etc. : a PART of the results.
This patch allows the user to do, in a subclass of admin.ModelAdmin :
def add_view(self, *args):
return super(AdminModel, self).add_view(fields_filters={'category':
{'parent__id':2, 'status':1}}, *args)
def change_view(self, *args):
return super(AdminModel,
self).change_view(fields_filters={'category': {'parent__id':2,
'status':1}}, *args)
So the category he can chooses are limited. Moreover, one of the *args
is the request, so it is possible to do 'parent__id':
request.GET.get('parent_id'). Possibilities are not limited, and the
dictionary allows the user to filter the related keys with the
django's firepower. This change is backward compatible and wouldn't
introduce any problem for the sites that work now. Except if I have
forgotten something ;-)

I may not explain very well since my English sucks, so if you want
more precisions, just ask them.


Reply all
Reply to author
0 new messages