0

I currently have 2 admin.py files.

  1. project/admin.py
  2. project/pages/basicpage/admin.py

I would like to use the registered classes inside the second admin.py along with the first admin.py such that they can both be reached at the same admin endpoint.

FILE ONE: project/admin.py

from django.contrib import admin
from project import models
from project.pages.basicpage import admin as BP_admin


@admin.register(models.Test)
class TestAdmin(admin.ModelAdmin):
    pass

FILE TWO: project/pages/basicpage/admin.py

from django.contrib import admin
from project import models

@admin.register(models.Platform)
class PlatformAdmin(admin.ModelAdmin):
    pass


@admin.register(models.Type)
class TypeAdmin(admin.ModelAdmin):
    pass

In file one, I have imported the second admin as BP_admin, not that it is used yet. However when I access my http://127.0.0.1:8000/admin endpoint, understandably I only can view the "Test" class that is registered in the first file. Any idea how to get my other 2 classes from my second file registered to the first file's endpoint?

Thanks!

2
  • Does this answer your question? Multiple ModelAdmins/views for same model in Django admin Commented Jan 12, 2021 at 22:08
  • not quite, this link allows the user to include ONE model across MULTIPLE endpoints. I want MULTIPLE models from different admin files to be routed to the SAME endpoint. Commented Jan 12, 2021 at 22:28

1 Answer 1

1

Admin is just the models so importing the models should be enough. You can just add:

from project.pages.basicpage import models as BP_models

@admin.register(models.Test)
...

@admin.register(BP_models.Platform)
class Platform(models.Platform):
    pass

You can also simplify and not use the class:

@admin.register(models.Test, BP_models.Platform,....)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.