#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 , 22 months ago
| Has patch: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:2 by , 22 months ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
PR