[Answer]-How to show related model fields when a foreign key is selected without submitting the form in django?

1👍

✅

Via javascript. You’d also need to set up a view that knows how to return a that related author.

Example psuedo code jQuery

$(".my-admin-input").change(function() {
    $.ajax({
        url: 'path-to-my-view',
        data: { author: $(this).val() },
        success: function(response) { $(".author-city").val(response.author) })
    });
});

def my_view(request):
    return Author.objects.get(pk=request.GET['author']).city

You can sneak JS into django admins by…

Leave a comment