Autocomplite for CharField
See original GitHub issueHello. i have the same problem in my project as https://github.com/yourlabs/django-autocomplete-light/issues/810
I want to autocomplite CharField of model
# models.py
class Pet(models.Model):
name = models.CharField(blank=False, null=False, default='Noname', max_length=50)
def __str__(self):
return self.name
# forms.py
class PetForm(ModelForm):
class Meta:
model = Pet
fields = [
'name',
]
widgets = {
'name': autocomplete.ListSelect2(url='pet_name_lookup'),
}
# admin.py
class PetAdmin(admin.ModelAdmin):
form = PetForm
admin.site.register(Pet, PetAdmin)
# view.py
class PetNameLookup(autocomplete.Select2ListView):
def create(self, text):
return text
def get_list(self):
result_list = []
if self.q:
data = Pet.objects.all().filter(name__icontains=self.q)[:10]
result_list = [x.name for x in data]
return result_list
On create admin form it works perfect, but when i try change pet name ListSelect2-widget set the field to blank.
Please help me. DAL is perfect!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
CharField autocompletes — django-autocomplete-light 2.2.9 ...
CharField autocompletes¶. django-tagging and derivates like django-tagging-ng provide a TagField , which is a CharField expecting comma separated tags.
Read more >How to use django-autocomplete-light on form with multiple ...
However, I am having issues with using it with the form, which has two char fields, both to use the same model called...
Read more >Using of django-autocomplete-light with CharField (not as tags)
I think, that the best way to resolve this problem is using of autocomplete, when manager is typing name of company, wich he...
Read more >Implement Search Autocomplete For Input Fields in Django
In this article we will learn how to fetch data from django models and give it feature like autocomplete. We will be using...
Read more >Auto-Complete - Django Packages
Completion for CharField/TextField widget based on ForeignKey completion list. Tp-Tham, Coming soon.. Show. 10, 25, 50, 100. entries. Search ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
What happens when you set self.fields[‘country’].initial ?
Excellent BorisPlus