[Solved]-Editing/Adding a Foreign Key object through inline display in the Django Admin


django_reverse_admin is a django module to solve this problem of needing inlines where the relationships are the ‘wrong’ direction.

You’ll need to add it to your requirements.txt and then import it:


from django_reverse_admin import ReverseModelAdmin

class Complete_Book(ReverseModelAdmin):
    # usual admin stuff goes here
    inline_type = 'tabular'  # or could be 'stacked'
    inline_reverse = ['book']  # could do [('book', {'fields': ['title', 'authors'})] if you only wanted to show certain fields in the create admin

admin.site.register(Book, Complete_Book)


Yes, this is actually quite easy. Just be sure to register a ModelAdmin for Book and admin will add a + button to the Complete_Book admin that will allow you to create a new Book.


Leave a comment