Closed EdwinTSalcedo closed 8 years ago
What database are you using ?
The Django ORM should be converting to the correct type itself. Previously the ajax-selects widget was converting the type by just guessing what was correct, but we decided that this was not the responsibility of the widget.
where exactly are you trying to do this:
return int(self.pk)
and the other thing you changed. can you link to it with a URL on github ?
somewhere in here:
https://github.com/crucialfelix/django-ajax-selects/blob/develop/ajax_select%2Flookup_channel.py#L98
you can and should just subclass LookupChannel and then implement that method if your database does not use int pks and the django orm is not correctly converting it to unicode.
Hi @crucialfelix,
I think everything works fine as far as rendering, but I am having a related problem on save. I believe the reason is that AutoCompleteSelectField only takes care of checking that the db objects still exists on clean, but then it simply returns the fetched object.
Therefore, unless your model has a convenient str or unicode representation, you will save an arbitrary string into your database. Is there a way to avoid this and always save your model pk in the db?
EDIT: my bad, I was simply using the wrong ORM mapping (a CharField instead of a ForeignKey).
yes it is supposed to return the object for the ForeignKey fields.
stale, closing.
Hi everyone! I've run into with this problem, when I want to update an object i got : [u"'Edwin Salcedo Aliaga - Hospital SSU - La Paz' must be an integer"]. So I changed the next in my model:
class Expediente(models.Model): paciente = models.ForeignKey(Paciente,db_column='paciente') establecimiento = models.ForeignKey(Establecimiento, db_column='establecimiento')
return by return int(self.pk), but then i got this: TypeError: coercing to Unicode: need string or buffer, int found.
It looked like a paradox xD. So I changed the next, return by return str(self.id) and ids = [pk_type(pk.pk) for pk in ids] in the file /root/virtenvs/sirssu/local/lib/python2.7/site-packages/ajax_select/lookup_channel.py in my virtualenvs. Please tell me if there is another way to do it in order not to modify the library! Thanks for django ajax selects!