Django views/class naming conventions
Just recently i changed my IDE to PyCharm (former was Sublime) and turns out all my views/classes are considered bad because they have underscore ( _ ) in their name.
My django-rest project views goes as follows:
# BuyersProject
path('bproject/', views.BP_List.as_view()), # Create BP | List user's BP
path('bproject/active/', views.BP_LastActive.as_view()), # Get last active BP
path('bproject/<int:pk>/', views.BP_Detail.as_view()), # Get specific BP
path('bproject/<int:pk>/filter/', views.BP_UpdateFilter.as_view()), # Update BP's filter
path('bproject/<int:pk>/step/', views.BP_StatusUpdate.as_view()), # BP status update
# BuyersProjectDetail
path('bproject/<int:pk>/detail/', views.BPD_List.as_view()), # BP's BPD List
path('bproject/detail/<int:pk>/', views.BPD_Detail.as_view()), # BPD Detail
path('bproject/detail/<int:pk>/close/', views.BPD_Close.as_view()), # Close BPD
# SellersProject
path('sproject/', views.SP_List.as_view()), # Create SP | List user's SP
path('sproject/<int:pk>/', views.SP_Detail.as_view()), # Get specific SP
path('sproject/<int:pk>/bc/', views.SP_BC_SellerUpdate.as_view()), # Update SP's BC
path('sproject/<int:pk>/step/', views.SP_StatusUpdate.as_view()), # SP status update
BP, BPD, SP, SPD and BC are achronyms for some of my models
My question: is it really that bad to have underscore in the name? should i rename my classes to match with naming conventions?
I am a strong believer that code should be readable for humans more than for machines.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler
I do care a lot about documenting, formatting and code structure/conventions (when working in a team it's really important) so i'm open to change if my current code is bad. Also, any advice/comment you make about the endpoints, views name or comments will be highly appreciated.
items in PascalCase usually do not have underscores (_
), that is for snake_case, but snake case is written in lowercase.
For classes, PEP-8 advises to use PerlCase:
Class names should normally use the CapWords convention.
so it should be BPList
, not BP_List
.
Furthermore in Django, class-based views usually have a …View
suffix. so you might want to rename BP_List
to BPListView
.