简体   繁体   中英

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]

我在管理员中看到了什么

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM