#26081: Understanding MyModel._meta.get_fields()
-------------------------------------+-------------------------------------
     Reporter:  guettli              |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  duplicate
     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):

 * status:  new => closed
 * resolution:   => duplicate


Old 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.

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.



 OK, I was not aware of #24317. I close this issue as a duplicate.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26081#comment:3>
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.b575593b1b945ccfd3ffda27d80394d7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to