[Django] #26985: Document restrictions on fields that can be referenced by ForeignKey.to_field

34 views
Skip to first unread message

Django

unread,
Aug 2, 2016, 4:33:03 AM8/2/16
to django-...@googlegroups.com
#26985: Document restrictions on fields that can be referenced by
ForeignKey.to_field
------------------------------------------------+------------------------
Reporter: bmispelon | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
As someone who's never used the feature before (I looked at the
documentation while investigating something else), it's not clear to me if
there are limitations or restrictions on what kind of fields can be used?

For example, does it need to be an `IntegerField` or can it be any field
(trying it out, it seems that a `CharField` works without issues).

One restriction which is caught by Django's validation framework is that
the field needs to have `unique=True` (this is the error fields.E311) but
I don't know if there are more.

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

Django

unread,
Aug 2, 2016, 8:19:48 AM8/2/16
to django-...@googlegroups.com
#26985: Document restrictions on fields that can be referenced by
ForeignKey.to_field
--------------------------------------+------------------------------------

Reporter: bmispelon | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26985#comment:1>

Django

unread,
Nov 13, 2016, 5:46:02 PM11/13/16
to django-...@googlegroups.com
#26985: Document restrictions on fields that can be referenced by
ForeignKey.to_field
-------------------------------------+-------------------------------------
Reporter: Baptiste Mispelon | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jonatas CD):

* owner: nobody => Jonatas CD
* status: new => assigned


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

Django

unread,
Nov 14, 2016, 4:24:25 AM11/14/16
to django-...@googlegroups.com
#26985: Document restrictions on fields that can be referenced by
ForeignKey.to_field
-------------------------------------+-------------------------------------
Reporter: Baptiste Mispelon | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jonatas CD):

* has_patch: 0 => 1


Comment:

Based on a search into the code, you can find uses with `CharField`,
`EmailField`, `IntegerField`, `PositiveIntegerField`, `UUIDField`.
But in all cases indeed the referenced field has to be `unique=True`.
Apart from that I didn't see any other restriction.
[https://github.com/django/django/pull/7553 Patch added] updating
documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/26985#comment:3>

Django

unread,
Nov 15, 2016, 11:22:06 AM11/15/16
to django-...@googlegroups.com
#26985: Document restrictions on fields that can be referenced by
ForeignKey.to_field
-------------------------------------+-------------------------------------
Reporter: Baptiste Mispelon | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.10
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"9da45ff352db1d1b7c64e5c724e9b0b31822b967" 9da45ff]:
{{{
#!CommitTicketReference repository=""
revision="9da45ff352db1d1b7c64e5c724e9b0b31822b967"
Fixed #26985 -- Doc'd that ForeignKey.to_field reference must be unique.
}}}

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

Django

unread,
Nov 15, 2016, 11:23:47 AM11/15/16
to django-...@googlegroups.com
#26985: Document restrictions on fields that can be referenced by
ForeignKey.to_field
-------------------------------------+-------------------------------------
Reporter: Baptiste Mispelon | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.10

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"af0f01558bb53553a1a7cd24f8121163c0069c85" af0f015]:
{{{
#!CommitTicketReference repository=""
revision="af0f01558bb53553a1a7cd24f8121163c0069c85"
[1.10.x] Fixed #26985 -- Doc'd that ForeignKey.to_field reference must be
unique.

Backport of 9da45ff352db1d1b7c64e5c724e9b0b31822b967 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26985#comment:5>

Reply all
Reply to author
Forward
0 new messages