Closed Pazitos10 closed 8 years ago
I don't think your Meta.widgets dict is configured correctly.
Shouldn't the key be the field name you want to specify the widget for ?
See: https://docs.djangoproject.com/en/1.9/topics/forms/modelforms/#overriding-the-default-fields
@jpic Yes! my bad, thanks for that!, I got this now:
...
from dal import autocomplete
...
class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
...
class Meta:
model = MyModel
fields = ('field',)
exclude = ['field-excluded']
widgets = {
'field': autocomplete.ModelSelect2(url='something-autocomplete')
}
Ooops, I think you should really try to make a form. You can't render a view object like that in a template !
def test_view(request):
# That won't work
search_field = SomethingAutocomplete()
# Should be an instance of your form
form = ''
Please, consider reading at least Django's documentation on forms:
https://docs.djangoproject.com/fr/1.9/topics/forms/
And perhaps even the example app:
https://github.com/yourlabs/django-autocomplete-light/tree/master/test_project/select2_outside_admin
Sorry again, I should updated that too:
def test_view(request):
search_field = SomethingAutocomplete()
form = MyForm()
context= {'form': form,'search_field': search_field}
return render(request, 'Something/test_template.html',context)
Remove search_fields.
Fix the template to render the form.
In doubt, refer to links posted above.
I'm warning you, if you don't read the documentation before commenting again i will have to close this, we can't do your homework :)
I solved it 10 mins ago with the example, thank you very much! ... Sorry again, wasn't my intention!
Thanks, I'm glad to know it works for you too ;)
Don't worry, you'll be in my situation a few years from now it will be your turn xD
And guess who was in your situation a few years ago ? hehe
I'm trying to use django-autocomplete-light outside the admin, so I got this:
in urls.py
Then, in forms.py:
Then in views.py
And last, in test_template.html:
But when I go to my site, all I got is this:
And if I inspect the elements:
Is nothing there, so I'm confused, what I'm doing wrong?
django version: 1.9 django-autocomplete-light version: 3.1.3