Django模型命名约定 [英] Django model naming convention
本文介绍了Django模型命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Django模型类的首选命名约定是什么?
What is the preferred naming convention for Django model classes?
推荐答案
Django模型只是Python类,因此Python命名 PEP-8 中详细说明的约定适用。
Django models are just Python classes, so the Python naming conventions detailed in PEP-8 apply.
例如:
- 人员
- 类别
- ZipCode
如果Django在创建相应表时未能正确地将类名复数,则可以轻松覆盖通过在内部META类中设置自定义 verbose_name_plural 字段来实现复数形式。例如:
If Django fails to pluralize the class name properly when creating the corresponding table, you can easily override the pluralization by setting a custom verbose_name_plural field in an inner META class. For example:
class Story(models.Model):
...
class Meta:
verbose_name_plural = "stories"
这篇关于Django模型命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文