#13790 closed (fixed)
Docs for CurrentSiteManager indicate an M2M field called "sites" will be auto-detected on a model when it won't
Reported by: | Gabriel Hurley | Owned by: | Gabriel Hurley |
---|---|---|---|
Component: | Contrib apps | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Throughout the Sites Framework docs the example models use sites = ManyToManyField(Site)
, and under the CurrentSiteManager section it indicates that CurrentSiteManager will be able to automatically discover either a ForeignKey called "site" or a ManyToManyField called "sites", when in fact the code only looks for a field called "site".
While it'd be an easy docs fix, it seems more valuable to fix the code for the manager to actually do what the docs say.
I'm happy to write up a patch and tests for it later.
Attachments (1)
Change History (7)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 14 years ago
Attachment: | 13790_CurrentSiteManager_patch.diff added |
---|
comment:2 by , 14 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Patch added which resolves the issues as follows:
- Uses a field name passed to the manager above all else
- If no name is given, it checks for a field named either "site" or "sites"
- Raises a ValueError if a field with the appropriate name is not found on the model
- Validates that the field found on the model is either a ForeignKey or ManyToManyField
- Adds a full set of new unit tests to cover the previously completely untested CurrentSiteManager.
Changes pass the full test suite, I don't foresee any backwards incompatibilities, and the code is now in line with the docs.
If anyone sees refinements for the code feel free to let me know, but this seemed like the most maintainable and extensible way to implement the field name validation.
comment:3 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
This patch looks good and applies for me. Marking as RFC.
comment:4 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I've got deja vu here... I addressed this documentation in #13168. Looks like the new text is just as misleading as the last lot.
However, agreed that the natural thing is to allow 'sites' as well. My take on the right implementation:
For bonus points, we could add extra validation protection; the current implementation is very lax, in that it allows *any* field called site (including an integer field, etc).