Opened 6 months ago

#28011 new Bug

Correct Field.hidden docs regarding what fields are hidden

Reported by: Tim Graham Owned by: nobody
Component: Documentation Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no 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 (0)

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