Django

Code

Ticket #3646 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

ABSOLUTE_URL_OVERRIDES docs are inconsistent with how they actually work

Reported by: ubernostrum Assigned to: jacob
Milestone: Component: Documentation
Version: SVN Keywords:
Cc: nsteinmetz@gmail.com Triage Stage: Ready for checkin
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by ubernostrum)

The docs for the ABSOLUTE_URL_OVERRIDES setting state that the keys in that dictionary should be of the form app_label.modelname, with the model name capitalized, but the code in django/db/models/base.py which curries get_absolute_url looks for app_label.module_name, and module_name is normalized to lower-case by that point.

So, for example, the docs say to use weblog.Entry as a key in ABSOLUTE_URL_OVERRIDES, but get_absolute_url will actually look for weblog.entry.

I'm of two minds on how to solve this; the naive solution is to have the curried get_absolute_url look for opts.module_name.capitalize(), since that will make it consistent with the examples in the docs, but it's entirely possible that someone will create a model class with an all-lowercase name (which is, I assume, why module_name is normalizing it to lowercase), in which case the better solution is to change the docs.

Attachments

3646.diff (0.7 kB) - added by ubernostrum on 03/05/07 14:38:32.
Documentation patch to resolve this

Change History

03/03/07 12:04:46 changed by ubernostrum

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

03/03/07 12:07:19 changed by ubernostrum

  • description changed.

03/03/07 12:08:44 changed by ubernostrum

  • description changed.

03/03/07 12:10:36 changed by ubernostrum

(and in a wonderfully ironic twist of fate, this is partially my fault, because it was my documentation patch in #3226 which made the docs inconsistent with the actual code...)

03/03/07 16:31:58 changed by anonymous

  • cc set to nsteinmetz@gmail.com.

03/04/07 01:13:05 changed by mtredinnick

  • stage changed from Design decision needed to Accepted.

Of the two choices, we should prefer fixing the docs: use the lower-case version and point out that people must use the lower-case version.

The capitalize() version won't work for a model called MyModel. Camel- case class names is pretty common in Python (even PEP-8 compatible).

The ideal solution would be a third option: take the key and lower-case it before comparing to the module_name. Then people can use the real Python import path in the settings file and not have to worry about Django's slightly odd "real men don't use capital letters" approach to lower-casing every name in sight. Can't immediately see how to do that in just a line or two in django. db.models.base.get_absolute_url(), though.

03/05/07 14:38:32 changed by ubernostrum

  • attachment 3646.diff added.

Documentation patch to resolve this

03/05/07 14:38:44 changed by ubernostrum

  • owner changed from adrian to jacob.
  • component changed from Metasystem to Documentation.
  • stage changed from Accepted to Ready for checkin.

03/07/07 06:23:01 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [4672]) Fixed #3646 -- Corrected documentation for ABSOLUTE_URL_OVERRIDES. Patch from James Bennett.


Add/Change #3646 (ABSOLUTE_URL_OVERRIDES docs are inconsistent with how they actually work)




Change Properties
Action