#17605 closed Bug (fixed)
It is not documented how to work with ManyToMany relations
Reported by: | Mikhail Korobov | Owned by: | Ramiro Morales |
---|---|---|---|
Component: | Documentation | Version: | 1.3 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
The docs for ManyToMany relations used to rely on doctests ("See the Many-to-many relationship model example for a full example.")
https://docs.djangoproject.com/en/dev/topics/db/models/#many-to-many-relationships
But since https://code.djangoproject.com/changeset/14285/ these doctests were removed. So ManyToMany relations are now almost undocumented (both in dev version of docs and in all old versions of docs).
Because this is a regression from Django 1.3 I've marked it as a release blocker.
Attachments (4)
Change History (14)
by , 13 years ago
Attachment: | 17605-1.diff added |
---|
comment:1 by , 13 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
I added some code examples in the docs. Don't know if it is enough to cover most usages, but it's a start at least. Double-check my English, as usual.
by , 13 years ago
Attachment: | 17605-2.diff added |
---|
Alternative patch adding a topics/db/examples/ hierarchy
comment:2 by , 13 years ago
In the '-2' patch I simply converted to ReST syntax the models.py files of the modeltests for m2m, FK and one2one relationships freezing them with the state they were an the point their respective doctests were removed.
Also, removed all references to tests/modeltests/*
from topics/db/models.txt
.
comment:3 by , 13 years ago
Patch needs improvement: | set |
---|
comment:4 by , 13 years ago
The second patch is a good starting point. However, in my opinion the examples should be simplified. There's too much tests for various field lookups which are already documented elsewhere. If these are meant to be examples, they must be short, simple and useful. Also a few more lines of text would be welcome.
by , 13 years ago
Attachment: | patch_17605.diff added |
---|
Trying to simplify the examples, probably needs some more tweaking.
comment:5 by , 13 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 13 years ago
Patch needs improvement: | unset |
---|
comment:7 by , 13 years ago
Patch needs improvement: | set |
---|
The style shows that these documents used to be doctests, but it's a good basis IMO.
topics/db/models.txt
- This page still refers to the "Many-to-one relationship model tests", but that link is pointing to a regular documentation page. Use the same wording as the other "See also" blocks?
topics/db/examples/many_to_one.txt
a = Article(id=None, ...
: this isn't idiomatic; I'd skip theid
kwarg entirely.- "Article objects have access to their related Reporter objects:": this was demonstrated just above, I'd reorganize this part a bit
>>> Article.objects.filter(reporter=1)
: I didn't know this was supported, and it feels unclean. Plus, there are two ways to do the same thing. Do we really want to document this possibility?>>> Reporter.objects.filter(article=1)
: same comment
topics/db/examples/many_to_many.txt
- "Add a Publication directly via publications.add...": shouldn't that be "publications.create"?
>>> Article.objects.filter(publications=1)
: same comment againpublications__in=[1,2]
: missing space after the commapublications__in=[p1,p2]
: missing space after the comma>>> Publication.objects.filter(article=1)
: same comment againarticle__in=[1,2]
: missing space after the commaarticle__in=[a1,a2]
: missing space after the comma- "After the delete, the QuerySet cache needs to be cleared, and the referenced objects should be gone": this sounds like an internal implementation detail, not something a developer using Django should worry about
topics/db/examples/one_to_one.txt
- "Restaurant.objects.all()" should be in fixed width font.
I hope this helps!
Adding ManyToManyField examples