Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26081 closed Uncategorized (duplicate)

Understanding MyModel._meta.get_fields() — at Version 3

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 Thomas Güttler)

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 (3)

comment:1 by Thomas Güttler, 9 years ago

Component: DocumentationDatabase layer (models, ORM)
Description: modified (diff)

comment:2 by Tim Graham, 9 years ago

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.

comment:3 by Thomas Güttler, 9 years ago

Description: modified (diff)
Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top