42π
The default widget for Many-to-many field in admin or widgets with filter_vertical
or filter_horizontal
property allows you to add new item. There is a green β+β sign near the field to open a popup window and add new Director instance.
But if you need the inline style admin you should reference to the through-model. If you donβt specify the custom model Django creates a simple model with 2 foreign keys to Director and Film.
So you can try to create inline like
class DirectorInline(admin.TabularInline):
model = Film.director.through
extra = 3
This will not raise an exception and will generate an inline form, but you will have to select directors from drop-down list. I think you can overwrite this by using custom form.
6π
The simplest way to add a β+β button next to a ManyToManyField is to make sure that both objects are registered in your admin.py file. Otherwise Django wonβt create a form for the second type of object
admin.py
admin.site.register(Film)
admin.site.register(Director)
- [Django]-React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)
- [Django]-Django.db.migrations.exceptions.InconsistentMigrationHistory
- [Django]-Django's ManyToMany Relationship with Additional Fields