> Firstly, that's not how you specify custom permissions. In fact, I'm > surprised that doesn't raise some kind of error in Python. Have a look > athttp://docs.djangoproject.com/en/dev/ref/models/options/#permissions >
I was trying right, just make the mistake when type the post (now realize that capitalize "permission" and don't put quote in SomeModel.custom_permission too sorry ;)). > The syntax inside the Meta inner class is > > permissions = <sequence of two-element sequences> > > so a list of tuples or a tuple of tuples or a list of lists. But the > "permissions = " bit is very important. You have to assign to the > Meta.permissions attribute. > > Secondly, although permissions are specified on a model, they are > actually stored on a per-application basis. So you should make sure that > each custom permission you create is unique within that particular > application. You then query if a user has that permission like this: > > if user.has_perm('testapp.custom_permission'): > # ... > > That is, you pass a string to has_perm() which is the application name > followed by the permission name. > > However, that isn't quite the full story. The above is how it works with > Django's default authentication backend (and it's the contrib.auth > application that actually does the permission checking). Other auth > backends can implement what they accept as an argument to has_perm() in > whatever way they choose. So in some case, you might well be passing in > an object there. But that's slightly more advanced usage and only comes > into play if you're using a custom authentication backend that provides > its own permission handling code. > > As a general rule, the above (passing a string of > <app_name>.<permission_name> to has_perm()) is all you'll need to > remember. > > Regards, > Malcolm Excellent explanation, I recommend copy/paste to Doc ( http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.user_passes_test or http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.models.User.has_perm or better http://docs.djangoproject.com/en/dev/ref/models/options/#permissions ) because 'polls.can_vote' and 'package.codename' are not so explicit way to tell "although permissions are specified on a model, they are actually stored on a per-application basis." and " As a general rule, the above (passing a string of <app_name>.<permission_name> to has_perm ()) is all you'll need to remember." Cheers and thank a lot! Frank Abel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---