On Thu, Apr 16, 2009 at 5:13 PM, Dave Benjamin <dave.benja...@gmail.com>wrote:

>
> On Apr 11, 9:29 am, Dave Benjamin <dave.benja...@gmail.com> wrote:
> > Is it possible to exclude columns from the popup list view?
>
> I may have answered my own question. It looks like the popup is
> generated from the changelist_view method of ModelAdmin, and this
> method gets the request as a parameter. I was able to modify the
> list_display attribute (which seems to be used as an instance
> attribute even though it normally starts out as a class attribute)
> before the change list gets generated. However, it seems like the
> ModelAdmin instance is saved and reused, so I have to code for both
> the popup and non-popup states, and I wonder if mutating the instance
> is a thread-safe operation. Anyway, here's what I came up with:
>
> class CustomUserAdmin(UserAdmin):
>    # ...
>
>    def changelist_view(self, request, *args, **kwargs):
>        is_popup = admin.views.main.IS_POPUP_VAR in request.GET
>        if is_popup:
>            self.list_display = [
>                u'username',
>                u'last_name',
>                u'first_name',
>                u'is_active',
>                u'last_login',
>            ]
>            self.list_display_links = [u'username']
>        else:
>            self.list_display = [
>                u'username',
>                u'last_name',
>                u'first_name',
>                u'is_active',
>                u'is_staff',
>                u'date_joined',
>                u'last_login',
>            ]
>            self.list_display_links = [u'username']
>        return super(CustomUserAdmin, self).changelist_view(request,
> *args, **kwargs)
>
> admin.site.unregister(User)
> admin.site.register(User, CustomUserAdmin)
>
> >
>
This code isn't threadsafe.  If you use your application in a multithreaded
application they will "cross the streams" so to speak and you will see
things rendred with the wrong list display.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to