Opened 7 years ago

Closed 4 weeks ago

Last modified 4 weeks ago

#28011 closed Bug (fixed)

Correct Field.hidden docs regarding what fields are hidden

Reported by: Tim Graham Owned by: Adam Johnson
Component: Documentation Version: 1.10
Severity: Normal 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

The Field.hidden docs say, "Boolean flag that indicates if a field is used to back another non-hidden field’s functionality (e.g. the content_type and object_id fields that make up a GenericForeignKey)." This seems inaccurate:

from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models

class TaggedItem(models.Model):
    tag = models.SlugField()
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, related_name='tagged_items')
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

>>> TaggedItem._meta.get_field('object_id')
<django.db.models.fields.PositiveIntegerField: object_id>
>>> TaggedItem._meta.get_field('content_type')
<django.db.models.fields.related.ForeignKey: content_type>

(object_id and content_type aren't hidden).

There's a related discussion in the Options.get_fields() docs that also needs some correction.

Another thing I noticed is that Field.hidden is only consulted for relational fields. Removing Field.hidden and GenericForeignKey.hidden doesn't result in any crash of get_fields() because those attributes are never consulted.

Change History (5)

comment:1 by Adam Johnson, 4 weeks ago

Has patch: set
Owner: changed from nobody to Adam Johnson
Status: newassigned

comment:2 by Mariusz Felisiak, 4 weeks ago

Triage Stage: AcceptedReady for checkin

comment:3 by Mariusz Felisiak <felisiak.mariusz@…>, 4 weeks ago

Resolution: fixed
Status: assignedclosed

In 7ba6c9ed:

Fixed #28011 -- Corrected Field.hidden docs.

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 weeks ago

In 23c7cbf:

[5.0.x] Fixed #28011 -- Corrected Field.hidden docs.

Backport of 7ba6c9edc50dc989fc5c306b541636249b952f93 from main

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 weeks ago

In f65f8ab:

Refs #28011 -- Removed ForeignObjectRel.is_hidden().

Note: See TracTickets for help on using tickets.
Back to Top