[Django] #26081: Understanding MyModel._meta.get_fields()

98 views
Skip to first unread message

Django

unread,
Jan 13, 2016, 8:53:38 AM1/13/16
to django-...@googlegroups.com
#26081: Understanding MyModel._meta.get_fields()
-------------------------------+--------------------
Reporter: guettli | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
We try to understand what `MyModel._meta.get_fields()` does.

Pull request coming to improve the docs.

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

Django

unread,
Jan 13, 2016, 9:10:06 AM1/13/16
to django-...@googlegroups.com
#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

unread,
Jan 13, 2016, 5:06:22 PM1/13/16
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------

Comment (by timgraham):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26081#comment:2>

Django

unread,
Jan 14, 2016, 3:04:32 AM1/14/16
to django-...@googlegroups.com
#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

unread,
Jan 28, 2016, 3:10:33 AM1/28/16
to django-...@googlegroups.com
#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 TZanke):

* cc: tzanke@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/26081#comment:4>

Reply all
Reply to author
Forward
0 new messages