Custom HTML Template for Django 2.0 Autocomplete Widget
Is it possible to create a custom HTML Template, like Django-Autocomplete-Lite does by passing '*data-html:True*' attribute and overriding it's '*get_default_label*' method? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1b591683-972d-4f1e-82ec-f803c6d86f81%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: autocomplete widget
Hi The widget source code is here, its pretty easy to see wats going on, if im dealing with forms i spend a lot of time in here: http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py And the docs are here: http://docs.djangoproject.com/en/1.1/ref/forms/widgets/#ref-forms-widgets http://docs.djangoproject.com/en/1.1/ref/forms/fields/#ref-forms-fields http://docs.djangoproject.com/en/1.1/ref/forms/api/#ref-forms-api cheers sam On Sun, Jan 10, 2010 at 5:13 AM, nameless <xsatelli...@gmail.com> wrote: > Thank you it's very useful. > Now I need to create a new widget in django but I don't know where is > the documentation about widget. > > > On Jan 9, 4:42 pm, "esatterwh...@wi.rr.com" <esatterwh...@wi.rr.com> > wrote: >> What I do for auto completers ( in general ) is point the widget at a >> URL that returns JSON objects and the parse the objects client side. >> For the user object your function might look like this: >> >> from django.utils import simplejson >> from django.contrib.auth.models import User >> from django.http import HttpResponse >> >> def ajax_get_users(request): >> users = User.objects.filter(username__istarstswith = request.POST >> ['q']) >> return HttpResponse(simplejson.dumps([dict(username=u.username, >> id=u.pk) for u in users]), mimetype='text/javascript')) >> >> should get something that looks like this >> >> [ >> {username:'username',id:4}, >> {username:'username2',id:5} >> ] >> >> [urls.py] >> url(r'^/member/search/$', 'path.to.views.ajax_get_users', >> name="myapp_ajax_user_search"), >> >> if you have your widget set up to include the needed javascript that >> should be it. Honestly, the JS parts is more difficult than the django >> part. >> >> Hope that makes sense >> On Jan 8, 1:46 pm, nameless <xsatelli...@gmail.com> wrote: >> >> > Hi at all, I am looking for a working simple example on autocomplete >> > widget for foreign key in Django. I have found many example but I >> > don't understand and doesn't work. >> >> > This is my model: >> >> > class profile(models.Model): >> >> > user = models.ForeignKey(User, unique=True) >> >> > class profileForm(ModelForm): >> >> > user = forms.CharField(widget=AutoCompleteWidget()) >> >> > class Meta: >> > model = profile >> >> > I wish an AutoCompleteWidget working for this example. >> >> > Could anyone help me pleaseee ? >> >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: autocomplete widget
Thank you it's very useful. Now I need to create a new widget in django but I don't know where is the documentation about widget. On Jan 9, 4:42 pm, "esatterwh...@wi.rr.com" <esatterwh...@wi.rr.com> wrote: > What I do for auto completers ( in general ) is point the widget at a > URL that returns JSON objects and the parse the objects client side. > For the user object your function might look like this: > > from django.utils import simplejson > from django.contrib.auth.models import User > from django.http import HttpResponse > > def ajax_get_users(request): > users = User.objects.filter(username__istarstswith = request.POST > ['q']) > return HttpResponse(simplejson.dumps([dict(username=u.username, > id=u.pk) for u in users]), mimetype='text/javascript')) > > should get something that looks like this > > [ > {username:'username',id:4}, > {username:'username2',id:5} > ] > > [urls.py] > url(r'^/member/search/$', 'path.to.views.ajax_get_users', > name="myapp_ajax_user_search"), > > if you have your widget set up to include the needed javascript that > should be it. Honestly, the JS parts is more difficult than the django > part. > > Hope that makes sense > On Jan 8, 1:46 pm, nameless <xsatelli...@gmail.com> wrote: > > > Hi at all, I am looking for a working simple example on autocomplete > > widget for foreign key in Django. I have found many example but I > > don't understand and doesn't work. > > > This is my model: > > > class profile(models.Model): > > > user = models.ForeignKey(User, unique=True) > > > class profileForm(ModelForm): > > > user = forms.CharField(widget=AutoCompleteWidget()) > > > class Meta: > > model = profile > > > I wish an AutoCompleteWidget working for this example. > > > Could anyone help me pleaseee ? > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: autocomplete widget
What I do for auto completers ( in general ) is point the widget at a URL that returns JSON objects and the parse the objects client side. For the user object your function might look like this: from django.utils import simplejson from django.contrib.auth.models import User from django.http import HttpResponse def ajax_get_users(request): users = User.objects.filter(username__istarstswith = request.POST ['q']) return HttpResponse(simplejson.dumps([dict(username=u.username, id=u.pk) for u in users]), mimetype='text/javascript')) should get something that looks like this [ {username:'username',id:4}, {username:'username2',id:5} ] [urls.py] url(r'^/member/search/$', 'path.to.views.ajax_get_users', name="myapp_ajax_user_search"), if you have your widget set up to include the needed javascript that should be it. Honestly, the JS parts is more difficult than the django part. Hope that makes sense On Jan 8, 1:46 pm, nameless <xsatelli...@gmail.com> wrote: > Hi at all, I am looking for a working simple example on autocomplete > widget for foreign key in Django. I have found many example but I > don't understand and doesn't work. > > This is my model: > > class profile(models.Model): > > user = models.ForeignKey(User, unique=True) > > class profileForm(ModelForm): > > user = forms.CharField(widget=AutoCompleteWidget()) > > class Meta: > model = profile > > I wish an AutoCompleteWidget working for this example. > > Could anyone help me pleaseee ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
autocomplete widget
Hi at all, I am looking for a working simple example on autocomplete widget for foreign key in Django. I have found many example but I don't understand and doesn't work. This is my model: class profile(models.Model): user = models.ForeignKey(User, unique=True) class profileForm(ModelForm): user = forms.CharField(widget=AutoCompleteWidget()) class Meta: model = profile I wish an AutoCompleteWidget working for this example. Could anyone help me pleaseee ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.