[Django]-Django admin list_display foreign key id without join

8👍

Foreign key’s id is available as <name>_id attribute so you can show ids via custom method:

class CDRAdmin(admin.ModelAdmin):

    list_display = ('call_id_display', 'order_id_display', 'start_date', 'remark')

    def call_id_display(self, obj):
       return obj.call_id
    call_id_display.short_description = 'Call ID'

    def order_id_display(self, obj):
       return obj.order_id
    order_id_display.short_description = 'Order ID'

Leave a comment