1👍
✅
finally i found the solution as its written wrongly in the documentation doc,
in admin.py
you should add this code, in my cade my admin calss is orderAdmin
def get_form(self, request, obj=None, **kwargs):
form = super(orderAdmin,self).get_form(request,obj,**kwargs)
autoselect_fields_check_can_add(form,self.model,request.user)
return form
👤mohd
1👍
The documentation shows the exact same text as the accepted answer.
https://github.com/crucialfelix/django-ajax-selects#example
Either
- your
Admin
class must inherit fromAjaxSelectAdmin
- you should use
AjaxSelectAdmin
as a mixin (multiple inheritance) - you can insert the
autoselect_fields_check_can_add
in yourget_form()
You should only need to do the third case if you need to implement get_form
for your own other purposes. It’s better to just inherit from AjaxSelectAdmin
.
The other possible explanation for why you do get an ADD icon is that you don’t have permission to add the object. autoselect_fields_check_can_add
checks using Django’s standard admin permissions.
Source:stackexchange.com