#26081 closed Uncategorized (duplicate)
Understanding MyModel._meta.get_fields()
Reported by: | Thomas Güttler | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | tzanke@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
We try to understand what MyModel._meta.get_fields()
does.
https://docs.djangoproject.com/en/1.9/ref/models/meta/#django.db.models.options.Options.get_fields
Returns a tuple of fields ...
get_fields() returns two different types of objects:
- django.db.models.fields
- ManyToOneRel, OneToOneRel or ManyToManyRel
If you print the items of get_fields() you see the difference:
<ManyToOneRel: foo.tickettype> <ManyToOneRel: foo.ticket> ... foo.Tickettype.id foo.Tickettype.parent foo.Tickettype.name ...
According to the docs you get "fields". But you get first Rel-Objects and then DB-fields.
The example in the docs is the same: https://docs.djangoproject.com/en/1.9/ref/models/meta/#django.db.models.options.Options.get_fields
(<ManyToOneRel: admin.logentry>, <django.db.models.fields.AutoField: id>, ...
We are missing a common base class.
The wording is confusing since you speak of "field" but get_fields() returns fields and rels.
OK, I was not aware of #24317. I close this issue as a duplicate.
Change History (4)
comment:1 by , 9 years ago
Component: | Documentation → Database layer (models, ORM) |
---|---|
Description: | modified (diff) |
comment:2 by , 9 years ago
comment:3 by , 9 years ago
Description: | modified (diff) |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
comment:4 by , 9 years ago
Cc: | added |
---|
Replacing "rel" objects with real fields is the subject of #24317. Until then, I'm not sure how to proceed documentation-wise since rel objects aren't explicitly public API.