1👍
✅
You are not doing it the “django way”. you need to write your own widget for the author field.
and do something like this:
class BookForm():
class Meta:
model = Book
fields = ('title', 'author')
widgets = {
'author': YourFacebookLikeWidgetClass,
}
Now, your widget is responsible for doing all your cool stuff, (ajax call, rendering the results…etc) , but in the end, it will return the right value for the form. (the author ID)
Read more about django widgets
The problem is that there isnt a lot of info about writing your own widgets, but you can always ask here, and watch the source code of some django widgets. (It is not vert complicated to write your own 🙂 )
Source:stackexchange.com