python 3.x - Django 1.11 admin form add search box to oneToOne field -




i have user, admin , employee models, both employee , admin related user model onetoone field in admin form have 1 field "user"

instead of having drop down field users have search box when search specific user find him , choose him admin.

how?
tried add user's fields admin's form couldn't
tried inline thing, parent_link in admin's model... couldn't find solution
minimise search through long users list adding search box field

i have solved type of problem using django-ajax-selects package. hope you.

app/admin.py:

from ajax_select import register, lookupchannel  @register('users') class userslookup(lookupchannel):      model = user      def get_query(self, q, request):           return self.model.objects.filter(username__icontains=q)  class employeeadminform(forms.modelform):     user = autocompleteselectfield('users', required=false,                                    help_text=none)      class meta:          model = employee          fields = '__all__' 

settings.py

ajax_lookup_channels = {     'users'  : {'model': 'auth.user', 'search_field': 'username'}, } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -