[Django]-Best naming convention for handling multiword Django models?

3πŸ‘

βœ…

It is your personal choice. But if you are working in a team I would say you should be applying the Python PEP8 standard of coding; that way all members of the team are using the same process and naming conventions to write their code.

In this instance:

yet_another_model = YetAnotherModel()

Variables names should be lower-case, underscore separated. With class names using the camel casing naming convention.

and

'yet_another_model_detail'

Url names should be treat like a variable name or function name, lower-case separated with _ (underscores).

Templates:

Whilst there is no defined naming convention for templates I treat the naming the same as a function name. So in these cases I go for lower-case with underscore word separation.
I also keep the templates inside of the django apps (sometimes, I will have a templates directory which will have a directory for each app name).

I also stick the CRUD type at the end of the filename.

For example:

<app_div>/user_profile.html
<app_dir>/user_profile_update.html
<app_dir>/user_profile_view.html
<app_dir>/user_profile_delete.html
πŸ‘€Matt Seymour

Leave a comment