[Django] #27377: Prepopulated Fields in Django Admin

16 views
Skip to first unread message

Django

unread,
Oct 24, 2016, 7:38:27 AM10/24/16
to django-...@googlegroups.com
#27377: Prepopulated Fields in Django Admin
-------------------------------+-------------------------------------------
Reporter: Malik A. Rumi | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Keywords: prepopulated_fields, admin.py
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-------------------------------------------
I don't know if this should be a bug report or a feature request.

I know that some variation on this question has been asked and answered
many times on Stack Overflow. Usually, however, it is about using a
foreign key. This is not my question. "prepopulated_fields doesn’t accept
DateTimeField, ForeignKey, nor ManyToManyField fields."
https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.prepopulated_fields

By implication, the docs are saying OneToOne fields are ok. This makes
even more sense where the inherited models are a concrete subclass of a
concrete base and we are really talking about a single object. For
example, a Place can be a Restaurant, and a Restaurant can have a closed
off, separate Bar where kids are not allowed.
https://docs.djangoproject.com/en/1.10/topics/db/models/#one-to-one-
relationships

However, admin.py is looking for a string to concatenate, not a filtered
queryset leading to a related field or object. Furthermore, it expects
that string to match the name of an existing field on the instant model,
not some other model, even if they are the same object. How, then, can one
use a OneToOne field or model in admin.py? I posted this to SO myself, and
got ZERO responses. http://stackoverflow.com/questions/39778945/django-
prepopulated-fields-inheritance

Yes, I know about model-utils and polymorphic. But if I am reading the
docs correctly, this should be possible without resort to those tools.
Besides, both are aimed primarily at queries, and say nothing directly
about this specific issue with prepopulated fields in admin.py. Please
advise. Thanks.

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

Django

unread,
Oct 26, 2016, 12:55:09 PM10/26/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------

Reporter: Malik A. Rumi | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

`OneToOneField` is a subclass of `ForeignKey`, so as far as I see,
[https://github.com/django/django/blob/f734e2d4b2fc4391a4d097b80357724815c1d414/django/contrib/admin/checks.py#L399-L406
a system check error] will occur. I guess the error message could be
clarified since it confused you.

As far as getting answers to usage questions goes, please
[wiki:TicketClosingReasons/UseSupportChannels].

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

Django

unread,
Oct 26, 2016, 10:37:16 PM10/26/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Malik A. Rumi):

Replying to [comment:1 Tim Graham]:


> `OneToOneField` is a subclass of `ForeignKey`, so as far as I see,
[https://github.com/django/django/blob/f734e2d4b2fc4391a4d097b80357724815c1d414/django/contrib/admin/checks.py#L399-L406
a system check error] will occur. I guess the error message could be
clarified since it confused you.
>
> As far as getting answers to usage questions goes, please
[wiki:TicketClosingReasons/UseSupportChannels].

Ok. Thx.

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

Django

unread,
Nov 1, 2016, 6:59:49 AM11/1/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: Sudheesh
Type: | Singanamalla
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sudheesh Singanamalla):

* owner: nobody => Sudheesh Singanamalla
* status: new => assigned


Comment:

As far as what I understand from the discussion so far and the
description, the fact that `prepopulated_fields` doesn't accept `OneToOne`
fields needs to be explicitly mentioned in the documentation as well as an
update to the following line
https://github.com/django/django/blob/f734e2d4b2fc4391a4d097b80357724815c1d414/django/contrib/admin/checks.py#L402
mentioning
{{{
else:
if isinstance(field, (models.DateTimeField, models.ForeignKey,
models.ManyToManyField)):
return [
checks.Error(
"The value of '%s' refers to '%s', which must not
be a DateTimeField, "
"a ForeignKey, a OneToOneField or a
ManyToManyField." % (label, field_name),
obj=obj.__class__,
id='admin.E028',
)
]
else:
return []
}}}

Would this solve the issue ?

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

Django

unread,
Nov 1, 2016, 7:42:00 AM11/1/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: Sudheesh
Type: | Singanamalla
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Yes, please keep the comma before "or" in the message. A test could also
be added.

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

Django

unread,
Nov 1, 2016, 3:47:26 PM11/1/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: Sudheesh
Type: | Singanamalla
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Malik A. Rumi):

Thanks guys. This will be a big help to all the literal minded people out
there, like me.

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

Django

unread,
Dec 6, 2016, 2:28:34 PM12/6/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* owner: Sudheesh Singanamalla => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/27377#comment:6>

Django

unread,
Dec 12, 2016, 10:20:23 PM12/12/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Henry Dang):

* owner: (none) => Henry Dang


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27377#comment:7>

Django

unread,
Dec 17, 2016, 11:47:55 PM12/17/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.10

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Henry Dang):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/7710 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27377#comment:8>

Django

unread,
Dec 19, 2016, 8:34:03 AM12/19/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.10
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"6af23a4521fcf80aec7c5ee3988914423c7dfccd" 6af23a4]:
{{{
#!CommitTicketReference repository=""
revision="6af23a4521fcf80aec7c5ee3988914423c7dfccd"
Fixed #27377 -- Clarified that prepopulated_fields doesn't work with
OneToOneField.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27377#comment:9>

Django

unread,
Dec 19, 2016, 10:14:15 AM12/19/16
to django-...@googlegroups.com
#27377: Clarify that prepopulated_fields doesn't work with OneToOneField
-------------------------------------+-------------------------------------
Reporter: Malik A. Rumi | Owner: Henry
Type: | Dang
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.10

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
prepopulated_fields, admin.py |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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

In [changeset:"12c1d6fe8f03f068f6010e3c8e0f441bf2567e7c" 12c1d6f]:
{{{
#!CommitTicketReference repository=""
revision="12c1d6fe8f03f068f6010e3c8e0f441bf2567e7c"
Refs #27377 -- Fixed reverse query name clash in test model.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27377#comment:10>

Reply all
Reply to author
Forward
0 new messages