* cc: davenaff@… (added)
* easy: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:57>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* easy: 0 => 1
Comment:
Hmm, just meant to add me to cc list - didn't mean to change easy
pickings. Setting easy pickings.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:58>
* easy: 1 => 0
Comment:
Hmm, that message is confusing lots of people. (it was technically 'null'
before, which counts as 'false', which was correct, but then your update
forced it to be explicitly 'false' i.e. unset, which was still correct.
Until you toggled it :-)
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:59>
Comment (by Stanislas Guerra <stan__at__slashdev.me>):
Patch against trunk added.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:61>
Comment (by ramiro):
Latest path is using !AdminSite's `root_path` that doesn't exit anymore
(see r16575). Also, I don't like it is reintroducing using
`'../../..'`-style paths we are trying to move away from (see r16578,
#15294)
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:62>
Comment (by Stan <stan__at__slashdev.me>):
Replying to [comment:62 ramiro]:
> Latest path is using !AdminSite's `root_path` that doesn't exit anymore
(see r16575). Also, I don't like it is reintroducing using
`'../../..'`-style paths we are trying to move away from (see r16578,
#15294)
The latest patch is `root_path` and `../..` free.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:63>
Comment (by julien):
This looks really good! However, it really needs to support
`ManyToManyFields` before it can be included in core. A list builder
widget, as specified in `[1]`, could be a nice solution.
`[1]` http://wiki.jqueryui.com/w/page/12137993/ListBuilder
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:64>
Comment (by julien):
See also #10293 re: ManyToMany raw_id_fields.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:65>
* cc: carlos.palol@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:66>
* cc: stan@… (added)
Comment:
Replying to [comment:64 julien]:
> This looks really good! However, it really needs to support
`ManyToManyFields` before it can be included in core. A list builder
widget, as specified in `[1]`, could be a nice solution.
>
> `[1]` http://wiki.jqueryui.com/w/page/12137993/ListBuilder
That's nice indeed but for the sake of consistency the same interface
should also be ported to the ForeignKey's raw_id. This mean to completely
rethink this patch.
And what about the non-javascript users ?
Merging #10293 looks more reasonable and simpler to me.
But I like the idea of an auto-completion (and so my users) !
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:67>
Comment (by Stanislas <stan@…>):
ManyToMany raw_id_field: Maybe we could add a "Clear" button for each
labeled object in order to javascriptly remove its Id in the input ?
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:68>
* cc: Twidi (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:69>
Comment (by anonymous):
This patch looks great!
What's the status of this patch? Is any work being done to include it in
core?
Thanks a lot!
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:70>
Comment (by jacob):
#10293 was a dup.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:71>
Comment (by Stan@…):
Add patch against 1.4.5.
Fix a bug contrib.admin.ManyToManyRawIdWidget#label_for_value(self, value,
name) when value was empty.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:72>
Comment (by Stanislas):
Fixed `Clear' button malfunction in admin raw_id fields.
Github branch : https://github.com/Starou/django/tree/ticket_7028_1_4
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:73>
* needs_docs: 0 => 1
* type: New feature => Uncategorized
* easy: 0 => 1
* stage: Accepted => Unreviewed
Comment:
1
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:74>
* status: new => closed
* type: New feature => Uncategorized
* resolution: => fixed
Comment:
1
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:75>
Comment (by ogpcludi <sample@…>):
1
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:76>
Comment (by ogpcludi <sample@…>):
1
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:77>
Comment (by julien):
I've worked on a reasonably straightforward implementation (1) for this
inspired from DrMeers' "cooked_ids" (2). I've also written a number of
selenium tests. It has the advantage of preserving raw_id_fields if you
still want them (for whatever reason), while allowing you to use the more
user-friendly version (here called "token_fields").
The main piece that's still missing from this implementation is the
ability to work with non-integer primary keys.
Any feedback?
(1) https://bitbucket.org/drmeers/django-
generic/src/bd20113dce83a5ba6db30a96f0493b93e3aeea17/generic/admin/mixins/cooking.py
(2)
https://github.com/jphalip/django/compare/django:04489c7dbf8f69de84ca272a0a1710e7b6067e9d...ticket-7028
-token-fields
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:74>
Comment (by stanislas.guerra@…):
@Julien : I have backported your patch to 1.5.x and tested it. The concern
I have is about the lack of the hyperlink to *admin_change* (but maybe it
is safer to not provide it rather provide it badly (i.e. permission
check)) and the clean button for the ForeignKey.
Anyway, looks good to me !
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:75>
Comment (by stanislas.guerra@…):
For those interested :
https://github.com/Starou/django/compare/django:stable/1.5.x...ticket_7028_1_5_jphalip?expand=1
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:76>
Comment (by stanislas.guerra@…):
Replying to [comment:75 stanislas.guerra@…]:
> [...] and the clean button for the ForeignKey.
>
My mistake, the clean button is there.
> Anyway, looks good to me !
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:77>
Comment (by stanislas.guerra@…):
But this does not works with inlines. Using {{{token_fields}}} into an
{{{InlineModelAdmin}}} gives 404 in ajax call to render the FK unicode().
For example, I have added in the test the following models:
{{{
class TicketDealer(models.Model):
name = models.CharField(blank=False, max_length=20)
website = models.URLField(blank=True)
def __unicode__(self):
return self.name
class TokenFieldTicketDealerEvent(models.Model):
"""
A model that has token fields in the admin inline.
"""
dealer = models.ForeignKey(TicketDealer)
event = models.ForeignKey(TokenFieldEvent)
}}}
And the admin:
{{{
class TokenFieldTicketDealerEventAdminInline(admin.StackedInline):
model = models.TokenFieldTicketDealerEvent
token_fields = ('dealer',)
class TokenFieldEventAdmin(admin.ModelAdmin):
token_fields = ['main_band', 'supporting_bands']
inlines = (TokenFieldTicketDealerEventAdminInline,)
}}}
With the TestCase:
{{{
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class
AdminInlineTokenWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
available_apps = ['admin_widgets'] +
AdminSeleniumWebDriverTestCase.available_apps
fixtures = ['admin-widgets-users.xml']
urls = "admin_widgets.urls"
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
def setUp(self):
band = models.Band.objects.create(id=42, name='Bogey Blues')
event = models.TokenFieldEvent.objects.create(id=11,
main_band=band)
dealer1 = models.TicketDealer.objects.create(id=12, name="Cheap
Horse", website="www.ch.com")
dealer2 = models.TicketDealer.objects.create(id=21, name="Decent
Buy", website="www.db.com")
models.TokenFieldTicketDealerEvent.objects.create(event=event,
dealer=dealer1)
super(AdminInlineTokenWidgetSeleniumFirefoxTests, self).setUp()
def test_foreignkey(self):
self.admin_login(username='super', password='secret',
login_url='/')
self.selenium.get(
'%s%s' % (self.live_server_url,
'/admin_widgets/tokenfieldevent/11/'))
main_window = self.selenium.current_window_handle
}}}
It fires ''http://localhost:8081/admin_widgets/tokenfieldevent/objects-by-
ids/tokenfieldticketdealerevent_set-0-dealer/12/'' -> 404
I though it was just a bug in retrieving the field name into
RelatedObjectLookups.js#updateTokenField() and had it patched like that:
{{{
diff --git
a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
index 5d8a19c..b333cfd 100644
--- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
+++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
@@ -108,7 +108,7 @@ var updateTokenField = function(field) {
var $field = $(field);
$field.hide();
var container = $field.closest('div');
- var field_name = $field.attr('name');
+ var field_name = getTokenFieldName(field);
var pks = encodeURI($field.val());
if (pks) {
var objects_url = '../objects-by-ids/' + field_name + '/' + pks +
'/'; // FIXME: hard-coded url
@@ -128,6 +128,18 @@ var updateTokenField = function(field) {
}
};
+var getTokenFieldName = function(field) {
+ // inline fields are prefixed.
+ var $ = django.jQuery;
+ var $field = $(field);
+ var rx_prefix = new RegExp("\\\w+-\\\d{1,2}-\(\\\w+\)");
+ var field_name = $field.attr('name');
+ if (field_name.match(rx_prefix)) {
+ field_name = field_name.match(rx_prefix)[1];
+ }
+ return field_name;
+}
+
var removeToken = function(removeLink, field) {
var $ = django.jQuery;
var li = $(removeLink).parent();
}}}
Now It fires an Ajax call to
''http://localhost:8081/admin_widgets/tokenfieldevent/objects-by-
ids/dealer/12/'' -> 404, ''dealer'' not in
''TokenFieldEventAdmin.token_fields''.
This is because in RelatedOjectLookup.js (l.158) the ajax call is on
''../objects-by-ids/et/caetera/'' which is in the "path" of the parent
ModelAdmin.
In fact, there is not any url to call at this point because
{{{InlineModelAdmin}}} can't register any url.
Any idea on the direction to take ? allow InlineModelAdmin to register url
? Where (under its ModelAdmin or not) ?
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:78>
* cc: depaolim@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:79>
* keywords: raw-id-fields nfa-someday design_ux => raw-id-fields nfa-
someday design_ux raw_id_fields
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:80>
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:81>
* cc: cmawebsite@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:82>
* cc: hugo@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:83>
* status: new => closed
* resolution: => wontfix
Comment:
I think it doesn't make sense to add this enhancement while also adding a
new autocomplete widget (#14370). After the autocomplete widget is added,
we might deprecate `raw_id_fields` in some later release.
--
Ticket URL: <https://code.djangoproject.com/ticket/7028#comment:84>