Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename "post" (noun) to "blog post" #1648

Open
das-g opened this issue Feb 23, 2020 · 4 comments
Open

rename "post" (noun) to "blog post" #1648

das-g opened this issue Feb 23, 2020 · 4 comments

Comments

@das-g
Copy link
Member

das-g commented Feb 23, 2020

As noted in #1642 (comment) and #1642 (comment), there's three things that can be easily mistaken for oneanother:

  • the English noun "post" (in context of the tutorial: a blog post)
  • the English verb "post" (as in "I'm posting this to my blog")
  • the HTTP verb POST

Mixing up the latter two isn't really an issue, as they refer to the same concept anyway, only on different levels of abstraction. Mixing up the first with any of the others two can lead to profound confusion though, as the object referred to by the noun is the result of the actions referred to by the verbs.

To avoid this ambiguity, especially in code where one cannot rely on sentence structure to keep these words and concepts apart, let's base all variable names referring to the first (the noun) on "blog post" rather than just "post".

This means:

  1. rename class Post to BlogPost.
  2. rename variables and arguments holding an instance of Post from post to blog_post
  3. rename variables and arguments holding an QuerySet of Post from posts to blog_posts
  4. rename views, corresponding templates and URL "name"s (not the URLs path patterns themselves):
    • post_listblogpost_list
    • post_detailblogpost_detail
    • post_newnew_blogpost
    • post_editedit_blogpost
@nikhiljohn10
Copy link
Contributor

@das-g I have an alternative suggestion. Use namespace. It's very straight forward if you want to make multiple apps.

Simply add app_name = 'blogpost'

For example:

app_name = 'blogpost'
urlpatterns = [
    path('', views.list, name='list'),
    path('post/<int:pk>/', views.detail, name='detail'),
    path('post/new/', views.create, name='create'),
    path('post/<int:pk>/edit/', views.update, name='update'),
    path('psot/<int:pk>/delete/', views.delete, name='delete'),
]

with this, we can use the following:

{% url 'blogpost:list' %}
reverse('blogpost:list')

{% url 'blogpost:detail' %}
reverse('blogpost:detail')

{% url 'blogpost:create' %}
reverse('blogpost:create')

{% url 'blogpost:update' %}
reverse('blogpost:update')

{% url 'blogpost:delete' %}
reverse('blogpost:delete')

Of course, this needs an explanation about the namespace concept in a layman's term. What do you think about it?

I agree to rename the class with BlogPost instead of Post

@das-g
Copy link
Member Author

das-g commented Nov 13, 2020

I have an alternative suggestion. Use namespace.

I like that idea. 👍 It's quite in line with the Zen of Python (PEP 20), whose 19th aphorism proclaims:

Namespaces are one honking great idea -- let's do more of those!

@nikhiljohn10
Copy link
Contributor

@das-g I am pushing commits for namespace change as well in different PR: master...jwaladiamonds:namespace

@nikhiljohn10
Copy link
Contributor

Namespace related changes can not be merged unless the PR #1681 is resolved. Otherwise, lots of conflicts are going to arise from it.

@ekohl Can you please look into that PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants