Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reassign a model to a different app for display only purposes in Django Admin

I know I can change the display title for a model in Django Admin using

    class Meta:
        verbose_name='Custom Model Name Here'

However, is there a way to display which app heading a model is displayed under?

For example, if I create a custom user model Users in a new app also called users then the default user model goes from Authentication and Authorization > Users to Users > Users.

I would like to retain it under the original heading Authentication and Authorization > Users.

enter image description here

I have read this answer which suggests changes the app verbose_name, however it only changes the verbose name of the app associated with the model. I want to show the model in a different group on the admin panel. You can see the issue that approach takes here:

enter image description here

like image 889
alias51 Avatar asked Jul 20 '19 14:07

alias51


People also ask

How do I change app label in Django admin?

Rename the folder which is in your project root. Change any references to your app in their dependencies, i.e. the app's views, the urls.py and settings.py files. Edit the database table django_content_type with the following command: UPDATE django_content_type SET app_label='' WHERE app_label=''


1 Answers

You could set up a proxy model

In app_1.models.py

class MyModel(models.Model):
    ...

In app_2.models.py

from app_1.models import MyModel

class MyModelProxy(MyModel):
    class Meta:
        proxy = True

Then register the MyModelProxy in admin as normal

like image 146
HenryM Avatar answered Sep 24 '22 18:09

HenryM