Here are two: 'author-detail' vs 'author_update'
{{{
def get_absolute_url(self):
return reverse('author-detail', kwargs={'pk': self.pk})
}}}
from https://docs.djangoproject.com/en/1.8/topics/class-based-views
/generic-editing/#model-forms
some lines below the above link:
{{{
url(r'author/(?P<pk>[0-9]+)/$', AuthorUpdate.as_view(),
name='author_update'),
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25473>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0
Old description:
> Please use **one** form to refer to the update-view of
> a model.
>
> Here are two: 'author-detail' vs 'author_update'
>
> {{{
> def get_absolute_url(self):
> return reverse('author-detail', kwargs={'pk': self.pk})
> }}}
>
> from https://docs.djangoproject.com/en/1.8/topics/class-based-views
> /generic-editing/#model-forms
>
> some lines below the above link:
> {{{
> url(r'author/(?P<pk>[0-9]+)/$', AuthorUpdate.as_view(),
> name='author_update'),
> }}}
New description:
Please use **one** form to refer to the update-view of
a model.
Here are two: 'author-detail' vs 'author_update'
{{{
def get_absolute_url(self):
return reverse('author-detail', kwargs={'pk': self.pk})
}}}
from https://docs.djangoproject.com/en/1.8/topics/class-based-views
/generic-editing/#model-forms
some lines below the above link:
{{{
url(r'author/(?P<pk>[0-9]+)/$', AuthorUpdate.as_view(),
name='author_update'),
}}}
But first: The django core developers should decide which pattern should
be used in the docs:
foo-detail or foo_update.
When the decision was made, then all examples in the docs should use this
pattern.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:1>
Comment (by claudep):
Can you please clarify what is the precise object of this ticket? Is this
the hyphen vs underscore in the view name? Because detail and update views
are different views...
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:2>
Comment (by timgraham):
It looks to me like the complaint is that sometimes dashes are used in
`url()` names, sometimes underscores. If I had to cast a vote, I guess I'd
choose dashes based on Google's advice "We recommend that you use hyphens
(-) instead of underscores (_) in your URLs." and the fact that you might
want your URL names to roughly match the URLs themselves.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:3>
Comment (by guettli):
Yes, this ticket is not about technical details, it is about the Zen of
Python:
"There should be one-- and preferably only one --obvious way to do it."
It least the django docs should be consistently use hyphens xor underscore
for url names.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:4>
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Note that we cannot change some examples like `url(r'^reset/done/$',
auth_views.password_reset_complete, name='password_reset_complete')` in
`docs/ref/contrib/admin/index.txt` as Django templates use those names in
templates.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:5>
Comment (by amites):
or perhaps the scope of this ticket could be expanded to include updating
the bundled templates
perhaps add a DEPRECATED / duplicate of urlpatterns that include all the
old underscore naming?
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:6>
Comment (by wimfeijen):
Hi guys,
My preference would be to use underscores in stead of dashes, because we
are coupling urls to views, and in function based views, view names always
use underscores instead of dashes.
My personal preference is to have url names, view names and template names
the same, all using underscores.
My url patterns tend to differ anyway, containing dashes, slug regexes and
such.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:7>
Comment (by aaugustin):
The counter-argument is that using a different convention for different
types of objects makes it easier to search or replace one type and not the
others.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:8>
Comment (by guettli):
What kind of types do you have? Can you please list some. I could guess
what you mean, but I don't like guessing.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:9>
Comment (by aaugustin):
Here are the three conventions and the types they're commonly used for:
- `dash-separated`: URL names
- `underscore_separated`: FBV function names
- `CamelCase`: CBV class names and other classes: models, forms, etc.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:10>
Comment (by guettli):
You wrote "The counter-argument is that using a different convention for
different types of objects makes it easier to search or replace one type
and not the others."
I understood that there are different types of url-names. But that was my
mistake.
I guess I understood you now: You want dash-seperated of the url names,
since .. it makes it easier to search or replace one type and not the
others. Correct?
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:11>
Comment (by aaugustin):
Exactly. Sorry for not expressing that clearly.
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:12>
* status: new => assigned
* owner: nobody => Gayathrimenakath
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:13>
* cc: Gayathrimenakath (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:14>
* owner: Gayathrimenakath => elenaoat
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:15>
* owner: elenaoat =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:16>
* status: new => assigned
* owner: => thijsvandien
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:17>
* has_patch: 0 => 1
Comment:
Pull request at https://github.com/django/django/pull/5593
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:18>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"1679472165e840aef4c8c9ece2fbf4620b87beab" 16794721]:
{{{
#!CommitTicketReference repository=""
revision="1679472165e840aef4c8c9ece2fbf4620b87beab"
Fixed #25473 -- Changed underscores in url() names to dashes in docs.
To improve consistency, sample URL names that had underscores
in them now use dashes instead. That excludes URL names that
have some relation to the code, such as those generated by
the admin.
Thanks guettli for reporting this.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:19>
Comment (by Tim Graham <timograham@…>):
In [changeset:"f5e1d72de2e111ef2449f858b672c9cf4ecbb9ff" f5e1d72]:
{{{
#!CommitTicketReference repository=""
revision="f5e1d72de2e111ef2449f858b672c9cf4ecbb9ff"
[1.9.x] Fixed #25473 -- Changed underscores in url() names to dashes in
docs.
To improve consistency, sample URL names that had underscores
in them now use dashes instead. That excludes URL names that
have some relation to the code, such as those generated by
the admin.
Thanks guettli for reporting this.
Backport of 1679472165e840aef4c8c9ece2fbf4620b87beab from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:20>
Comment (by Tim Graham <timograham@…>):
In [changeset:"78a28cca200e6e03432bab9bf73856b8f778c6f0" 78a28cca]:
{{{
#!CommitTicketReference repository=""
revision="78a28cca200e6e03432bab9bf73856b8f778c6f0"
[1.8.x] Fixed #25473 -- Changed underscores in url() names to dashes in
docs.
To improve consistency, sample URL names that had underscores
in them now use dashes instead. That excludes URL names that
have some relation to the code, such as those generated by
the admin.
Thanks guettli for reporting this.
Backport of 1679472165e840aef4c8c9ece2fbf4620b87beab from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25473#comment:21>