Skip to content

Hide relationships whose related_name='+' (trac #22015) #2263

Closed
wants to merge 1 commit into from

3 participants

@Motiejus

If related_name of a ForeignKey/M2M relationship is '+', user explicitly asked Django to not create backwards relation. This should be taken into account when rendering admindocs.

@charettes charettes and 1 other commented on an outdated diff Feb 11, 2014
django/contrib/admindocs/views.py
accessor = rel.get_accessor_name()
+ # If related_name == '+', backwards relations are explicitly disabled.
+ if accessor == '+':
@charettes
Django member
charettes added a note Feb 11, 2014

Actually a relation is hidden if it ends with a '+'. Here rel has a is_hidden method that abstract this check.

@Motiejus
Motiejus added a note Feb 11, 2014

Good catch, thanks! Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Motiejus Motiejus Hide hidden related models
If related_name of a ForeignKey/M2M relationship ends with '+' (in other
words, related model is hidden from the other side), user explicitly
asked Django to *not* create backwards relation. This should be taken
into account when rendering admindocs.
98bd144
@timgraham
Django member

Could you please add a test?

@Motiejus

I would love to, however, currently only some internal helpers are tested; there is nothing to hook onto what produces 'output'. If there were, I would definitely add a test. But in this case I don't feel adventurous enough to set up a full-blown test suite for this contrib application* and so left my patch testless (and I am not doing the "full" work).

[*]: if I depended more on admindocs, I would certainly do that.

@timgraham
Django member

Ok, I've left a comment on the ticket to that effect to see if anyone else is interested in adding tests. Will close this PR for now.

@timgraham timgraham closed this Feb 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.