Django管理界面 - 自定义应用程序名称 [英] Django Admin Interface - Custom App Name

查看:89
本文介绍了Django管理界面 - 自定义应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在'Class Meta'中使用'app_label'可以解决这个问题。但是它不会在发出syncdb命令时创建表。因为应用程序名称与INSTALLED_APPS条目不匹配。有没有办法实现这两个(自定义应用程序名称和使用syncdb创建表)

Using the 'app_label' in the 'Class Meta' will solve this problem. But it won't create tables while issuing 'syncdb' command. Because the app name won't match with INSTALLED_APPS entry. Is there any way to achieve both (custom app name and creating tables with syncdb)

推荐答案

我没有尝试过,但是这里有一个解决方案,应该允许更改应用程序标签,同时使用 syncdb

I haven't tried this, but here there is a solution that should allow changing the app label while working with syncdb.

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"

这是有道理的,因为表的名称是显式的,所以在运行 syncdb 时,没有猜测。缺点是这两个 Meta 选项必须在应用程序的每个模型中指定。

This makes sense, since the name of the table is made explicit, so there is no guessing when running syncdb. The downside is that this two Meta options must be specified in every model of the app.

这篇关于Django管理界面 - 自定义应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆