Autocomplete in Django 1.11: Widget in Forms Library?

535 views
Skip to first unread message

guettli

unread,
Sep 20, 2016, 6:51:24 AM9/20/16
to Django developers (Contributions to Django itself)
I am happy that there will be support for autocomplete in the admin in 1.11, if this issue/pull-request gets resolved:

https://code.djangoproject.com/ticket/14370

https://github.com/django/django/pull/6385/

I looked at the changes of the docs of this pull request.

It seems that only the contrib module "admin" gets improved.

Is it planed to add an autocomplete widget in the django forms library?



Tim Graham

unread,
Sep 20, 2016, 7:30:33 AM9/20/16
to Django developers (Contributions to Django itself)
I haven't seen that proposal. This type of widget would be new territory for django.forms as none of the existing widgets require JavaScript. I lean toward keeping things that way, but I'm open to hearing counterarguments. Historically, Django avoided "blessing" any particular JavaScript libraries.

Cheng Chi

unread,
Sep 21, 2016, 12:21:15 AM9/21/16
to Django developers (Contributions to Django itself)
What about dynamic content datalist instead of complex autocomplete UI by JS libraries? We can use just jQuery or vanilla JS to make some AJAX requests and change datalist on the go.

Florian Apolloner

unread,
Sep 21, 2016, 2:25:53 AM9/21/16
to Django developers (Contributions to Django itself)


On Wednesday, September 21, 2016 at 6:21:15 AM UTC+2, Cheng Chi wrote:
What about dynamic content datalist instead of complex autocomplete UI by JS libraries? We can use just jQuery or vanilla JS to make some AJAX requests and change datalist on the go.

Cause it simply does not scale if you have more than a few entries.

Florian Apolloner

unread,
Sep 21, 2016, 2:28:11 AM9/21/16
to Django developers (Contributions to Django itself)
Ups sorry I hit send to fast. Datalists also do not work for multiple select afaik and worst of all there is no support in Safari etc… Our widget has to work everywhere more or less.

guettli

unread,
Sep 21, 2016, 6:28:32 AM9/21/16
to Django developers (Contributions to Django itself)


Am Dienstag, 20. September 2016 13:30:33 UTC+2 schrieb Tim Graham:
I haven't seen that proposal. This type of widget would be new territory for django.forms as none of the existing widgets require JavaScript. I lean toward keeping things that way, but I'm open to hearing counterarguments. Historically, Django avoided "blessing" any particular JavaScript libraries.


OK, I see you don't want widgets which require JS in django core. I can understand this.

But since contrib.admin includes the autocomplete, it could be possible to provide such a widget in contrib.admin.

My intention: since the admin includes JS for autocomplete, it would be nice to re-use this in custom apps.

I know that I can use third party libraries to get this. But if it is already in contrib.admin, it would be nice to avoid duplication....


 

Collin Anderson

unread,
Sep 30, 2016, 1:20:21 PM9/30/16
to django-d...@googlegroups.com
Hi,

"it could be possible to provide such a widget in contrib.admin".

The current PR provides a django.contrib.admin.widgets.AutocompleteSelect widget. Does that work?

You could subclass it to use a different URL instead of the built-in admin:autocomplete url if needed. My one worry is that if we end up adding more code to handle use cases different from the admin, we'll just end up re-inventing and maintaining django-select2. But, maybe simply re-using the widget or subclassing the widget is good enough?

Thanks,
Collin


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/a4411d55-6db2-4515-b680-0b8dfe03a3bd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Tim Graham

unread,
Sep 30, 2016, 1:37:28 PM9/30/16
to Django developers (Contributions to Django itself)
I was thinking about a similar issue when looking at Curtis's patch for an admin HStoreField widget [0]. It doesn't seem so nice to give contrib.postgres special treatment in the admin. Rather, I think the admin should have a hook to register custom widgets for arbitrary fields. If it provided that, I wonder if the autocomplete patch [1] could more easily be done as a third-party library.

[0] https://github.com/django/django/pull/6515
[1] https://github.com/django/django/pull/6385


On Friday, September 30, 2016 at 1:20:21 PM UTC-4, Collin Anderson wrote:
Hi,

"it could be possible to provide such a widget in contrib.admin".

The current PR provides a django.contrib.admin.widgets.AutocompleteSelect widget. Does that work?

You could subclass it to use a different URL instead of the built-in admin:autocomplete url if needed. My one worry is that if we end up adding more code to handle use cases different from the admin, we'll just end up re-inventing and maintaining django-select2. But, maybe simply re-using the widget or subclassing the widget is good enough?

Thanks,
Collin

On Wed, Sep 21, 2016 at 6:28 AM, guettli <guet...@gmail.com> wrote:


Am Dienstag, 20. September 2016 13:30:33 UTC+2 schrieb Tim Graham:
I haven't seen that proposal. This type of widget would be new territory for django.forms as none of the existing widgets require JavaScript. I lean toward keeping things that way, but I'm open to hearing counterarguments. Historically, Django avoided "blessing" any particular JavaScript libraries.


OK, I see you don't want widgets which require JS in django core. I can understand this.

But since contrib.admin includes the autocomplete, it could be possible to provide such a widget in contrib.admin.

My intention: since the admin includes JS for autocomplete, it would be nice to re-use this in custom apps.

I know that I can use third party libraries to get this. But if it is already in contrib.admin, it would be nice to avoid duplication....


 
On Tuesday, September 20, 2016 at 6:51:24 AM UTC-4, guettli wrote:
I am happy that there will be support for autocomplete in the admin in 1.11, if this issue/pull-request gets resolved:

https://code.djangoproject.com/ticket/14370

https://github.com/django/django/pull/6385/

I looked at the changes of the docs of this pull request.

It seems that only the contrib module "admin" gets improved.

Is it planed to add an autocomplete widget in the django forms library?



--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.

Johannes Hoppe

unread,
Oct 11, 2016, 8:20:46 AM10/11/16
to Django developers (Contributions to Django itself)
Hi there!

Regarding reusing the admin widget:
I would advice highly against it. It made for the admin and requires models to be registered there. It would be better to use django-select2, which is where the autocomplete_fields are originating from.

At the current point I don't see how we could add a more generic widget to Django outside of the admin. This would require ether a manual registration of models as autocomplete light does it, or another approach that doesn't rely on Django cache.
The only way I see at the moment, is if Widget.render() would be aware of the request. This way one could use the session as a persistent storage.
This is a bigger design decision tho.

James Pic

unread,
Oct 11, 2016, 9:03:06 AM10/11/16
to django-d...@googlegroups.com
On Tue, Oct 11, 2016 at 2:20 PM, Johannes Hoppe <in...@johanneshoppe.com> wrote:
At the current point I don't see how we could add a more generic widget to Django outside of the admin. This would require ether a manual registration of models as autocomplete light does it, or another approach that doesn't rely on Django cache.

In DAL v3 there is no need for model registration. Autocomplete widgets do take a URL as argument though. 
Reply all
Reply to author
Forward
0 new messages