9👍
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:
admin.py
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)
👤lynx
2👍
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.
- Django login redirect not working?
- DeleteView with a dynamic success_url dependent on id
- Bulk, partial updates with Django Rest Framework
Source:stackexchange.com