Is it possible to group models from different apps into 1 admin block?
For example, my structure is
project/
review/
models.py - class Review(models.Model):
followers/
models.py - class Followers(models.Model):
admin.py
In followers/admin.py
, I call
admin.site.register(Followers)
admin.site.register(Review)
This is to group them inside 1 admin block for administrators to find things easily.
I tried that, but Review
model isn't showing up inside Followers
admin block and I couldn't find documentation about this.
You can check the admin.py file in your project app directory. If it is not there, just create one. Edit admin.py and add below lines of code to register model for admin dashboard. Here, we are showing all the model fields in the admin site.
The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.
An admin view without a model is basically just a normal Django view using an admin template with a mock ModelAdmin instance, which is basically what you're doing. I've done this myself to create some custom admin-themed pages.
django-admin is Django's command-line utility for administrative tasks. This document outlines all it can do. In addition, manage.py is automatically created in each Django project.
Django Admin groups Models to admin block by their apps which is defined by Model._meta.app_label
. Thus registering Review
in followers/admin.py
still gets it to app review
.
So make a proxy model of Review
and put it in the 'review' app
class ProxyReview(Review): class Meta: proxy = True # If you're define ProxyReview inside review/models.py, # its app_label is set to 'review' automatically. # Or else comment out following line to specify it explicitly # app_label = 'review' # set following lines to display ProxyReview as Review # verbose_name = Review._meta.verbose_name # verbose_name_plural = Review._meta.verbose_name_plural # in admin.py admin.site.register(ProxyReview)
Also, you could put Followers
and Review
to same app or set same app_label
for them.
Customize admin view or use 3rd-part dashboard may achieve the goal also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With