0

I am using autocomplete_light in a django model form.

this is my model for the form

class Ca_dispensaries_item(TimeStampedModel):
  item = models.ForeignKey(Items)
  dispensary = models.ForeignKey(Ca_dispensaries)
  description = models.CharField(max_length=5000, null=True)

this is the form

class CamenuForm(autocomplete_light.ModelForm):
   class Meta:
     model = Ca_dispensaries_item
     exclude = ('dispensary',)
     autocomplete_fields = ('item',)

registered as

autocomplete_light.register(Items, search_fields=('item_name'))

when i try to enter some values in the item, as per the autocomplete feature, it starts searching but gives field error Cannot resolve keyword u'i' into field. Choices are: arizona_dispensaries_item, ca_dispensaries_item, colorado_dispensaries_item, created, id i dont know from where this i is coming from. also, dispensaries_items are some of the models. while created and id are field names

proprius
  • 502
  • 9
  • 20

1 Answers1

0

You have forgottent a comma! Change

search_fields=('item_name')

to

search_fields=('item_name',)

search_fields should be an iterable, so if it has the value ('item_name') (which is a string) it will get 'i', 't', 'e', etc (that's why you get the message Cannot resolve keyword u'i' into field)

Also, there are some serious problems with the names your models: I see that you have a model named Items and a model named Ca_dispensaries_item. You should not name your models in plural, so Items should be Item and you need to use CamelCase with class names, so Ca_dispensaries_item should be CaDispensariesItem``.

Serafeim
  • 14,962
  • 14
  • 91
  • 133
  • No problem! Please consider also my naming suggestions ! – Serafeim Dec 16 '14 at 11:07
  • Can you tell me how to add extra filter on the `item` depending on the value passed to the form as in "form = CamenuForm(request.POST or None, category=category)". I have tried using choices_for_request as well but i guess the method is not able to access the value passed – proprius Dec 17 '14 at 16:14
  • This is the link for problem: [link](http://stackoverflow.com/questions/27528414/how-to-create-a-dependant-drop-down-using-autocomplete-light) – proprius Dec 17 '14 at 16:15