GAE の django-nonrel で機能する役割ベースのアクセス許可を取得しようとしています。
おそらく、Users と Groups の間の暗黙の多対多の関係が原因で、そのままでは機能しないように見えたので、http://www.fhahn.com/writing/Django-s-を見つけてインストールしました。 Django-Nonrel を使用した許可システム。ドキュメントに従って、(djangotoolbox の後) INSTALLED_APPS に permission_backend_nonrel を追加し、settings.py の適切なクラスに AUTHENTICATION_BACKENDS を定義しました。
これにより、以前の問題 (「DatabaseError: このクエリはデータベースでサポートされていません。」) を回避できますが、非常に単純なサンプルを実行すると、必要だと思われるときに空のアクセス許可のセットを取得するため、まだ立ち往生しています。何かを取り戻している。以下は、私ができる限り簡単な例です。python manage.py シェルによって django フレームワークで起動されます。これは単純なポニー ショップです。ユーザーをグループに追加し、そのグループにアクセス許可を付与し、それらのアクセス許可がユーザーの一連のアクセス許可の一部として反映されていることを確認しようとしています。
>>> from django.contrib.auth.models import Group, Permission, User
>>> from django.contrib.contenttypes.models import ContentType
>>> from pony_shop.models import Pony
#Create the group:
>>> farmers = Group(name="Farmers")
>>> farmers.save()
>>> pony_ct = ContentType.objects.get(app_label='pony_shop', model='pony')
#Create the Permission
>>> can_twirl = Permission(name='Can Twirl', codename='can_twirl', content_type=pony_ct)
>>> can_twirl.save()
#Give the Permission to the Group
>>> farmers.permissions.add(can_twirl)
>>> farmers.save()
#Create the User
>>> francis = User(username='francis')
>>> francis.save()
#Put the user in the group
>>> francis.groups.add(farmers)
>>> francis.save()
#Get a pony object
>>> firefly = Pony(price=12, height=3, name='Firefly', color='fuscia')
>>> firefly.save()
>>> francis.get_all_permissions()
set([]) #<-- WHY?!?
#Just in case I needed to check the permissions against a pony object:
>>> francis.get_all_permissions(obj=firefly)
set([]) #<-- Still no joy
問題は、上記が機能しないのはなぜで、機能させるには何を変更する必要があるのかということです。
よろしくお願いします。