#26081: Understanding MyModel._meta.get_fields()
-------------------------------------+-------------------------------------
     Reporter:  guettli              |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by guettli):

 * needs_better_patch:   => 0
 * component:  Documentation => Database layer (models, ORM)
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> We try to understand what `MyModel._meta.get_fields()` does.
>
> Pull request coming to improve the docs.

New description:

 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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26081#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.72e306a0d33e0d11e871144fce086931%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to