Changes between Initial Version and Version 1 of Ticket #26081


Ignore:
Timestamp:
Jan 13, 2016, 8:08:06 AM (9 years ago)
Author:
Thomas Güttler
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #26081

    • Property Component DocumentationDatabase layer (models, ORM)
  • Ticket #26081 – Description

    initial v1  
    11We try to understand what `MyModel._meta.get_fields()` does.
    22
    3 Pull request coming to improve the docs.
     3https://docs.djangoproject.com/en/1.9/ref/models/meta/#django.db.models.options.Options.get_fields
     4
     5{{{
     6 Returns a tuple of fields ...
     7}}}
     8
     9get_fields() returns two different types of objects:
     10
     11  * django.db.models.fields
     12  * ManyToOneRel, OneToOneRel or ManyToManyRel
     13
     14If you print the items of get_fields() you see the difference:
     15
     16{{{
     17<ManyToOneRel: foo.tickettype>
     18<ManyToOneRel: foo.ticket>
     19...
     20foo.Tickettype.id
     21foo.Tickettype.parent
     22foo.Tickettype.name
     23...
     24}}}
     25
     26According to the docs you get "fields". But you get first Rel-Objects and then DB-fields.
     27
     28The example in the docs is the same: https://docs.djangoproject.com/en/1.9/ref/models/meta/#django.db.models.options.Options.get_fields
     29{{{
     30(<ManyToOneRel: admin.logentry>,
     31 <django.db.models.fields.AutoField: id>,
     32...
     33}}}
     34
     35We are missing a common base class.
     36
     37The wording is confusing since you speak of "field" but get_fields() returns fields and rels.
     38
     39
     40
Back to Top