Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a django admin widget for adding multiple foreign keys with an inline through_model

I have a basic many to many relationship of:

Song to Playlist with PlaylistMember as the through model

Now I am displaying the songs in the playlist detail view using an inline View that is a subclass of TabularInline:

class PlaylistMemberInline(TabularInline):
    model = PlaylistMember
    raw_id_fields = ('Sound',)


class PlaylistAdmin(TranslatableAdmin):
    ...
    inlines = [PlaylistMemberInline]

What I see in the admin

To add multiple sounds I have to click on "Add another Sound", and then find that sound on a popup. This is annoying in my case, as I can find all sounds I want to add, but then have to click one and go back to "Add another Sound".

Is there a widget where I can search for, select and then add multiple Objects?

like image 227
David Schumann Avatar asked Apr 15 '15 15:04

David Schumann


1 Answers

Django source code (1.8 branch here, line 254) suggests that you can add your ForeignKey to radio_fields or raw_id_fields, resulting in a different widget.

In this case, add the field name "Sound" to PlaylistMemberInline.raw_id_fields, consider adding it to PlaylistMemberInline.radio_fields.

like image 134
Freek Wiekmeijer Avatar answered Nov 14 '22 04:11

Freek Wiekmeijer