我做了一個查詢通道,使用Django的Ajax-選擇,對示範區的現場,用我的ModelForm,選擇字段,當我創建或編輯用戶配置。Django的 - AJAX-SELECT 403禁止
class FormRegisterProfile(forms.ModelForm):
class Meta:
model = UserProfile
exclude = ('user')
interests = make_ajax_field(UserProfile,'interests','areas2',help_text=True)
expertise = make_ajax_field(UserProfile,'expertise','areas2',help_text=True)
會發生什麼事是,當我與公司沒有管理權限,我得到的服務器
[16/Aug/2012 14:56:12] "GET /profile/ajax_lookup/areas2?term=g HTTP/1.1" 403 22
我url.py此行的用戶登錄
(r'^admin/lookups/', include(ajax_select_urls)),
(r'^profile/', include(ajax_select_urls)),
url(r'^profile/edit/$', 'mycu.views.EditUserProfile', {}, 'register.html'),
url(r'^admin/', include(admin.site.urls)),
我查詢頻道:
AJAX_LOOKUP_CHANNELS = {
'areas' : {'model':'mycu.areas', 'search_field':'type'},
'areas2' : ('mycu.lookups', 'AreasLookup'),
我的查找的.py
class AreasLookup(LookupChannel):
model = Areas
def get_query(self,q,request):
return Areas.objects.filter(Q(type__icontains=q)).order_by('type')
def get_result(self,obj):
u""" result is the simple text that is the completion of what the person typed """
return obj.type
def format_match(self,obj):
""" (HTML) formatted item for display in the dropdown """
return self.format_item_display(obj)
def format_item_display(self,obj):
""" (HTML) formatted item for displaying item in the selected deck area """
return u"%s" % (escape(obj.type))
沒有 'make_ajax_fields' 上的ModelForm線,我可以很容易地訪問示範區。
什麼,我沒有想出是:
什麼是管理/查找之間的關係
感謝,
其實我已經做了一個自定義的LookupChannel,我只是沒有在此線程寫道。我編輯我的職務,請再看一次,我沒有想出如何解決...... 感謝, – cleliodpaula 2012-08-16 17:58:45
你看了我的答案嗎?您需要更改'check_auth'以允許非職員用戶。 – 2012-08-16 18:03:44