overriding module caption names in django admin

北战南征 提交于 2019-12-06 16:58:44

问题


By default, the admin models are grouped by the app, and the app name is in the caption (accounts, auth, etc.). How to override the name in the caption without writing the admin templates?


回答1:


At the moment, django doesn't provide any easy way to do this. See this ticket.




回答2:


You can easily doing it through the metadata options app_label and db_table

class model_module1(models.model):
    [...]

    class Meta:
        app_label = "Cool module name"
        db_table = "module1_model"


class model_module2(models.model):
    [...]

    class Meta:
        app_label = "Cool module name"
        db_table = "module2_model"

If you configure tables names correctly you will see how your modules get grouped under the new label in the admin.

Ref: http://docs.djangoproject.com/en/dev/ref/models/options/#app-label




回答3:


This solution works for Django 2:

In apps.py file:

from django.apps import AppConfig

class Config(AppConfig):
    name = 'myapp'
    verbose_name = 'My App Name'

In settings.py file:

INSTALLED_APPS = [
    'myapp.apps.Config',
]



回答4:


This may help somewhat. You can change how the apps are grouped, although I don't think you can change the app name:

django-grappelli

http://code.google.com/p/django-grappelli/



来源:https://stackoverflow.com/questions/1453112/overriding-module-caption-names-in-django-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!