ない私が考える新しい質問を制限するが、ここでは行く:は確かに特定のユーザー/顧客へのページビューのアクセス
私のジャンゴベースの受注システムでは、各ユーザ(スタッフではありませんが)どのCustomerProfileオブジェクトに関連していますそのユーザーを正しいCustomerオブジェクトに一致させます。この顧客のユーザは、ログインして未処理の請求書を閲覧することができます。あなたはこのような何かに移動し、顧客の請求書を表示するには:
/請求書/顧客/ 97/
(得意先請求書の#97)結構ですが、私は、ユーザーように、いくつかの認証を組み込む必要があり
/請求書/顧客/ 92 /などを手動で入力して別の顧客の請求書を表示することはできません(請求書92は別の顧客に属します)。
私はこれを持っているが、それは本当に良いコードではありません(と動作しません):
def customer_invoice_detail(request, object_id):
user = threadlocals.get_current_user()
try:
userprofile = UserProfile.objects.get(user=user)
user_customer = userprofile.customer.id
except UserProfile.DoesNotExist:
user_customer = None
if (request.user.is_authenticated() and user_customer is not null) or request.user.is_staff():
invoice = CustomerInvoice.objects.get(pk=object_id)
product_list = CustomerInvoiceOrder.objects.filter(invoice=object_id)
context = {
'object': invoice,
'product_list': product_list,
}
return render_to_response("invoices/customer_invoice_detail.html", context, context_instance=RequestContext(request))
else:
return HttpResponse("You are not authorised to view this invoice")
は、これに対処するためのより良い/簡単な方法でなければなりません - 任意のアイデア?
乾杯