[英]Django naming convention for views/models as package
I split my views.py and models.py into submodule views/ and models/我将我的 views.py 和 models.py 分成子模块 views/ 和 models/
the module views.py is in plural.模块 views.py 是复数形式。 when it is split into submodule views/ the files have to be plural or singular?当它被分成子模块视图/文件必须是复数还是单数?
example, in the models/:例如,在模型/:
models/
employee.py
department.py
schedule.py
views/
employee.py
department.py
schedule.py
according to django, the files should be in plural, but in such situation, should i give each file name plural or singular?根据django,文件应该是复数,但在这种情况下,我应该给每个文件名复数还是单数?
Update: There are many apps in our project.更新:我们的项目中有很多应用程序。 and here is one app that has many models with many interdependent, so it makes sense to belong to a single app.这是一个具有许多相互依赖的模型的应用程序,因此属于单个应用程序是有意义的。 and we like things clean and nice, so we split them into submodule like views/ and models/.我们喜欢干净漂亮的东西,所以我们把它们分成子模块,比如 views/ 和 models/。
This is not a solution you want.这不是您想要的解决方案。
But splitting the project into small django apps will make more sense over here.但是将项目拆分成小的 django 应用程序在这里会更有意义。
I personally follow this structure and have seen many projects following the same我个人遵循这种结构,并且看到许多项目都遵循相同的结构
employee/
models.py
views.py
schedule/
models.py
views.py
department/
models.py
views.py
But your project structure is not allowing you to do then what you have added is also readable and makes sense.但是您的项目结构不允许您这样做,那么您添加的内容也是可读且有意义的。
I think naming model files in the singular would be reasonable, but with view-files it is worth thinking, because very often view can use several models inside itself, in such cases such file name can be misleading.我认为以单数命名模型文件是合理的,但是对于视图文件,值得考虑,因为视图通常可以在自身内部使用多个模型,在这种情况下,这样的文件名可能会产生误导。 I usually call view files based on the business logic they make.我通常根据它们制作的业务逻辑调用视图文件。
It's also a good idea to look towards splitting the project into django apps.考虑将项目拆分为 django 应用程序也是一个好主意。
I don't think there is any convention or guideline or for naming modules for views.我认为没有任何约定或指南或为视图命名模块。 It is more of a personal choice.这更多是个人选择。 Just pick singular or plural and use stick with it in on all places.只需选择单数或复数,并在所有地方使用坚持。
For picking a choice, you can see how you named your deepest layer in stack (model).为了选择一个选项,您可以看到您如何命名堆栈中最深的层(模型)。 If you have used Employee
for your employee model (which is more likely), use employee
for module.如果您已将Employee
用于您的员工模型(更有可能),请使用employee
作为模块。 If you have used Employees
use employees
.如果您使用过Employees
使用employees
。 If I was you, I would use singular name for module even if there are multiple classes (one for each of CRUD operation) in one file.如果我是你,即使在一个文件中有多个类(每个 CRUD 操作一个),我也会为模块使用单数名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.