Search code examples
pythondjangodjango-ajax-selects

django-postman + django-ajax-selects usage


So i have just started using django-postman==3.2.2 and i am trying to integrate auto-complete using django-ajax-selects==1.3.6 while using django-authtools==1.2.0 to have a custom user model with no luck.

settings.py

AJAX_LOOKUP_CHANNELS = {
    'postman_users': dict(model='authtools.user', search_field='email'),
}
POSTMAN_AUTOCOMPLETER_APP = {
    'arg_default': 'postman_users',
}
AUTH_USER_MODEL = 'authtools.User'

I tried changing from model='authtools.user to model='auth.user but it doesn't work.

urls.py

from ajax_select import urls as ajax_select_urls

url(r'^messages/lookups/',
        include(ajax_select_urls)),
url(r'^messages/', include('postman.urls')),

I then go to the built in postman view http://localhost:8000/messages/write/ and when i fill the recipients input nothing happens.

What am i missing? Isn't this supposed to work with just these settings?


Solution

  • As a workaround i ended up using django-autocomplete-light which i found much easier to use and understand than django-ajax-selects I then created my own extended form and passed to the write view:

    class MyCustomWriteForm(BaseWriteForm):
        recipients = autocomplete_light.ChoiceField(
            'UserAutocomplete', label='recipients')
    
        class Meta(BaseWriteForm.Meta):
            fields = ('recipients', 'subject', 'body')
    

    in my urls.py:

    url(r'^messages/write/(?:(?P<recipients>[^/#]+)/)?$', WriteView.as_view(form_classes=(MyCustomWriteForm, AnonymousWriteForm)), name='write'),
    

    I think this was about it.