Novice here.
I've been fiddling with django-selectable to do an autocomplete when searching for a user, and allowing for the user to be created if not found.
Correct me if I'm wrong but it looks like:
- If I use AutoCompleteWidget, I can define get_item_value to decide what is returned, but the setting allow_new = True won't call create_item()
- If I use AutoCompleteSelectField, it will call create_item(), but it will actually ignore get_item_value?(at least that is what is happening.)
Is there a way to combine both behavior so that:
When a user is found, it will actually return the username instead of the full name. And if no user is found, the call create_item() will be called.
Here is my lookup:
class MyUserLookup(ModelLookup):
model = MyUsers
search_fields = ('fullname__istartswith', )
def get_item_value(self, item):
# Display for currently selected item
return item.username
def get_item_label(self, item):
# Display for choice listings
return "%s (%s)" % (item.fullname, item.username)
def create_item(self, value):
# simply return a string to tell the view to redirect to create a new member
return "Create_new_member"
registry.register(MyUserLookup)