Hi,
I'm trying to setup some custom permissions for a Django application, but can't seem to get it working. The official documentation is a little scant, and doesn't mention (at least that I can find) how to actually set a permission? Based on a few 3rd party tutorials I found, I've extended the User class and it seems to work OK:
from django.db import models
from django.contrib.auth.models import User,UserManager
class CustomUser(User):
custom_field = models.CharField(max_length=250)
objects = UserManager()
class Meta:
permissions = (
('is_custom','Has a Custom Permission'),
)
When I try to set a permission however, it doesn't work:
>>> from project.custauth.models import CustomUser
>>> from django.contrib.auth.models import User, Permission
>>> user = CustomUser.objects.get(username='new.user')
>>> user
<CustomUser: new.user>
>>> custom_permission = Permission.objects.get(codename="is_custom")
>>> custom_permission
<Permission: custauth | custom user | Has a Custom Permission>
>>> custom_permission.save()
>>> user.user_permissions.add(custom_permission)
>>> user.save()
>>> user.has_perm(custom_permission)
False
>>> user.get_all_permissions()
set([])
Any ideas on what I'm doing wrong? I'm using Django 1.2.1 with Python 2.4.3. All input appreciated...