[Django] #26387: Related popup doesn’t open in a changelist when in raw_id_fields

31 views
Skip to first unread message

Django

unread,
Mar 21, 2016, 11:37:20 AM3/21/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when in raw_id_fields
---------------------------------+--------------------
Reporter: BertrandBordage | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
Suppose you have this admin class, where 'fk' is a ForeignKey field name:
{{{#!python
@register(YourModel)
class YourModelAdmin(ModelAdmin):
list_display = ['fk']
list_editable = ['fk']
raw_id_fields = ['fk']
}}}
When you open the changelist, everything is displayed normally, fk
consists in a field and a magnifying glass. But no javascript 'click'
event is bound to the glass, so the changelist of the related model opens
directly in the main window, not in popup.

Of course, it prevents the users from filling the field, the only
solutions being: to type the ID, or to open the change view, which may be
disabled if you want users to only use the changelist…

Bug experienced on all Django 1.9 versions, and probably master.

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

Django

unread,
Mar 21, 2016, 11:49:18 AM3/21/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+------------------------------------

Reporter: BertrandBordage | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.8
Severity: Release blocker | 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):

* needs_better_patch: => 0
* needs_tests: => 0
* severity: Normal => Release blocker
* version: 1.9 => 1.8
* needs_docs: => 0
* stage: Unreviewed => Accepted


Old description:

> Suppose you have this admin class, where 'fk' is a ForeignKey field name:
> {{{#!python
> @register(YourModel)
> class YourModelAdmin(ModelAdmin):
> list_display = ['fk']
> list_editable = ['fk']
> raw_id_fields = ['fk']
> }}}
> When you open the changelist, everything is displayed normally, fk
> consists in a field and a magnifying glass. But no javascript 'click'
> event is bound to the glass, so the changelist of the related model opens
> directly in the main window, not in popup.
>
> Of course, it prevents the users from filling the field, the only
> solutions being: to type the ID, or to open the change view, which may be
> disabled if you want users to only use the changelist…
>
> Bug experienced on all Django 1.9 versions, and probably master.

New description:

Suppose you have this admin class, where 'fk' is a ForeignKey field name:
{{{#!python
@register(YourModel)
class YourModelAdmin(ModelAdmin):

list_display = ['pk', 'fk']


list_editable = ['fk']
raw_id_fields = ['fk']
}}}
When you open the changelist, everything is displayed normally, fk
consists in a field and a magnifying glass. But no javascript 'click'
event is bound to the glass, so the changelist of the related model opens
directly in the main window, not in popup.

Of course, it prevents the users from filling the field, the only
solutions being: to type the ID, or to open the change view, which may be
disabled if you want users to only use the changelist…

Bug experienced on all Django 1.9 versions, and probably master.

--

Comment:

I found it necessary to include another field in `list_display` to
reproduce this. Otherwise on master, you'll get an error like `"The value
of 'list_editable[0]' refers to the first field in 'list_display'
('question'), which cannot be used unless 'list_display_links' is set."` I
edited the ticket description to include this.

Seems to be a regression in Django 1.8 the popup works on 1.7.

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

Django

unread,
Mar 21, 2016, 12:09:40 PM3/21/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+------------------------------------

Reporter: BertrandBordage | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by BertrandBordage):

The solution would be to partially include `admin/js/change_form.js` to
the changelist view.

I made a workaround for Django 1.9 (and probably all other versions).
Create a static file `admin/js/change_list.js` containing this:
{{{#!javascript
// FIXME: Remove this file, it’s a workaround to
https://code.djangoproject.com/ticket/26387

(function($) {
'use strict';
$(document).ready(function() {
$('.related-lookup').click(function(e) {
e.preventDefault();
var event = $.Event('django:lookup-related');
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
showRelatedObjectLookupPopup(this);
}
});
});
})(django.jQuery);
}}}
Then add a `media` property to your admin class:
{{{#!python
from django.forms import Media

class YourModelAdmin(ModelAdmin):
[…]

# FIXME: Remove this workaround to
https://code.djangoproject.com/ticket/26387
@property
def media(self):
return super(YourModelAdmin,
self).media + Media(js=['admin/js/change_list.js'])
}}}

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

Django

unread,
Mar 24, 2016, 7:59:16 AM3/24/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+-------------------------------------
Reporter: BertrandBordage | Owner: timgraham
Type: Bug | Status: assigned

Component: contrib.admin | Version: 1.8
Severity: Release blocker | 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):

* owner: nobody => timgraham
* status: new => assigned


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

Django

unread,
Mar 24, 2016, 7:56:10 PM3/24/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+-------------------------------------
Reporter: BertrandBordage | Owner: timgraham
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.8
Severity: Release blocker | 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 timgraham):

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
Mar 25, 2016, 2:09:44 PM3/25/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+-------------------------------------
Reporter: BertrandBordage | Owner: timgraham
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.8
Severity: Release blocker | 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:"acfaec3db5ba39de52f6e607e74343dccf72fba1" acfaec3d]:
{{{
#!CommitTicketReference repository=""
revision="acfaec3db5ba39de52f6e607e74343dccf72fba1"
Fixed #26387 -- Restored the functionality of the admin's raw_id_fields in
list_editable.
}}}

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

Django

unread,
Mar 25, 2016, 2:23:30 PM3/25/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+-------------------------------------
Reporter: BertrandBordage | Owner: timgraham
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.8
Severity: Release blocker | 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:"1f15d442bf59218fb62fd95cc065da1d9a14b577" 1f15d44]:
{{{
#!CommitTicketReference repository=""
revision="1f15d442bf59218fb62fd95cc065da1d9a14b577"
[1.9.x] Fixed #26387 -- Restored the functionality of the admin's
raw_id_fields in list_editable.

Backport of acfaec3db5ba39de52f6e607e74343dccf72fba1 from master
}}}

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

Django

unread,
Mar 25, 2016, 3:05:52 PM3/25/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+-------------------------------------
Reporter: BertrandBordage | Owner: timgraham
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.8
Severity: Release blocker | 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:"0496838e61ad85fd8f8bb081f20577342aa1f151" 0496838e]:
{{{
#!CommitTicketReference repository=""
revision="0496838e61ad85fd8f8bb081f20577342aa1f151"
[1.8.x] Fixed #26387 -- Restored the functionality of the admin's
raw_id_fields in list_editable.

Backport of acfaec3db5ba39de52f6e607e74343dccf72fba1 from master
}}}

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

Django

unread,
Mar 25, 2016, 3:35:26 PM3/25/16
to django-...@googlegroups.com
#26387: Related popup doesn’t open in a changelist when list_editable in
raw_id_fields
---------------------------------+-------------------------------------
Reporter: BertrandBordage | Owner: timgraham
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.8
Severity: Release blocker | 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 BertrandBordage):

Thank you very much for your work, Tim ! :)

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

Reply all
Reply to author
Forward
0 new messages