Re: raw_id_fields admin widget not showing search icon

2,302 views
Skip to first unread message

Russell Keith-Magee

unread,
May 16, 2013, 12:25:02 AM5/16/13
to django...@googlegroups.com


On Thu, May 16, 2013 at 6:34 AM, Adrián López Calvo <adrianlo...@gmail.com> wrote:


Hello,

I have the following code in my admin.py:

    class UserManagedGroupAdmin(admin.ModelAdmin):
        inlines = [MembershipInline]
        search_fields = ('name', 'leader__username', )
        list_display = ('__unicode__', 'leader', )
        filter_horizontal = ('permissions', )
        raw_id_fields = ('leader', )

    admin.site.register(UserManagedGroup, UserManagedGroupAdmin)


The magnifying glass icon for searching doesn't appear in the admin page.

Attatched image shows what I'm getting.

As you can see it's showing the unicode method of the model instead of the search icon I want.

Field `'leader'` is a `ForeignKey` to `Member`, a proxy model of the builtin `User`.

I've tried it with other `ForeignKey` fields and they worked as expected.

Could it be that django disables the search for `ForeignKeys` to `User` for security reasons, or am I doing something wrong?

The widget would be perfect for choosing users... I mean, I can't leave a huge select there with every user of my site.

You've defined the admin registration for the Have you got an admin registration for the UserManagedGroup model, but have you got an admin registration for Member? If you haven't said that Member can be displayed, Admin won't be able to provide a view to search for Member instances.

Yours,
Russ Magee %-)
 

Adrián López Calvo

unread,
May 16, 2013, 10:22:43 AM5/16/13
to django...@googlegroups.com
That was it, thank you Russell.

Any way to register that model exclusively for this functionality, without showing its page in the main menu?
It's only a proxy of User so the information is completely redundant...

Adrián López Calvo

unread,
May 16, 2013, 11:41:11 AM5/16/13
to django...@googlegroups.com
Nevermind, adding this to the ModelAdmin of my User proxy made the deal. Or so it seems.

def get_model_perms(self, request):
    return {}

Thanks again,
Adrián
Reply all
Reply to author
Forward
0 new messages