+ 1
Show many to many fields in Django
I have a room model which is a many to many field with user model . How can i show that in my admin
1 Answer
+ 1
Django has a feature of showing Many-to-many fields in the admin page. You just have to register the model. To register the model, go to admin.py in your app. If this line is not there, add it
from django.contrib import admin
Then import the models you want to register
from .models import <model_names>
Then to register each model, you have to do
admin.site.register(<model_name>)
If you want to add Many-to-many fields to your custom admin page, these links might be useful
https://medium.com/@yprashant158/how-to-edit-manytomanyfield-in-django-admin-list-display-page-4687ec428639
https://stackoverflow.com/questions/25776235/many-to-many-fields-view-on-django-admin
[Also, just a tip. I don't know what you're trying to make but I think a foreign key will be more apt for user and room]