1 | commit 1eadf1be1bf986794961407a26cbe408bcf4af13
|
---|
2 | Author: Antti Kaihola <akaihol+django@ambitone.com>
|
---|
3 | Date: Fri Jul 3 14:07:14 2009 +0300
|
---|
4 |
|
---|
5 | Fixed #11163 -- Editable raw ID field pop-up link now correct also in admin changelists
|
---|
6 |
|
---|
7 | diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
|
---|
8 | index 8297eca..e1660a2 100644
|
---|
9 | --- a/django/contrib/admin/options.py
|
---|
10 | +++ b/django/contrib/admin/options.py
|
---|
11 | @@ -139,7 +139,7 @@ class BaseModelAdmin(object):
|
---|
12 | Get a form Field for a ForeignKey.
|
---|
13 | """
|
---|
14 | if db_field.name in self.raw_id_fields:
|
---|
15 | - kwargs['widget'] = widgets.ForeignKeyRawIdWidget(db_field.rel)
|
---|
16 | + kwargs['widget'] = widgets.ForeignKeyRawIdWidget(db_field.rel, self.admin_site)
|
---|
17 | elif db_field.name in self.radio_fields:
|
---|
18 | kwargs['widget'] = widgets.AdminRadioSelect(attrs={
|
---|
19 | 'class': get_ul_class(self.radio_fields[db_field.name]),
|
---|
20 | diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
|
---|
21 | index 7ae5e64..960bb3c 100644
|
---|
22 | --- a/django/contrib/admin/widgets.py
|
---|
23 | +++ b/django/contrib/admin/widgets.py
|
---|
24 | @@ -101,14 +101,23 @@ class ForeignKeyRawIdWidget(forms.TextInput):
|
---|
25 | A Widget for displaying ForeignKeys in the "raw_id" interface rather than
|
---|
26 | in a <select> box.
|
---|
27 | """
|
---|
28 | - def __init__(self, rel, attrs=None):
|
---|
29 | + def __init__(self, rel, admin_site, attrs=None):
|
---|
30 | self.rel = rel
|
---|
31 | + self.admin_site = admin_site
|
---|
32 | super(ForeignKeyRawIdWidget, self).__init__(attrs)
|
---|
33 |
|
---|
34 | def render(self, name, value, attrs=None):
|
---|
35 | if attrs is None:
|
---|
36 | attrs = {}
|
---|
37 | - related_url = '../../../%s/%s/' % (self.rel.to._meta.app_label, self.rel.to._meta.object_name.lower())
|
---|
38 | + # TODO: DRY violation, copied code from
|
---|
39 | + # RelatedFieldWidgetWrapper.render() below to fix #11163
|
---|
40 | + rel_to = self.rel.to
|
---|
41 | + info = (rel_to._meta.app_label, rel_to._meta.object_name.lower())
|
---|
42 | + try:
|
---|
43 | + related_info = (self.admin_site.name,) + info
|
---|
44 | + related_url = reverse('%sadmin_%s_%s_changelist' % related_info)
|
---|
45 | + except NoReverseMatch:
|
---|
46 | + related_url = '../../../%s/%s/' % info
|
---|
47 | params = self.url_parameters()
|
---|
48 | if params:
|
---|
49 | url = '?' + '&'.join(['%s=%s' % (k, v) for k, v in params.items()])
|
---|