Hi Tom Thanks for replying .I looked at this http://parand.com/say/index.php/2010/02/19/django-using-the-permission-system/
and got that point. def register_user(data): > """ > This method is used to register a new user and create a user profile. > """ > password = hashlib.sha1(data['confirm_ password']).hexdigest() > > new_user = User(username=data['email'], email=data['email'], > is_staff=True > ) > new_user.set_password(data['confirm_password']) > # At this point i want to set the permission in choose permission box from the available user_permission box ! How can i do this ? > Basically i want to put some of the permissions into Choose permission Box from Available permission box from code and not manually by going to the admin. Thanks On Thu, Dec 6, 2012 at 5:20 PM, Tom Evans <[email protected]> wrote: > On Thu, Dec 6, 2012 at 8:10 AM, Nikhil Verma <[email protected]> > wrote: > > Hi All > > > > I am developing a simple app in which i have to play with user > permissions.I > > register a user(during a sign up process) with this method :- > > > > def register_user(data): > > """ > > This method is used to register a new user and create a user profile. > > """ > > password = hashlib.sha1(data['confirm_password']).hexdigest() > > > > new_user = User(username=data['email'], email=data['email'], > > is_staff=True > > ) > > new_user.set_password(data['confirm_password']) > > # At this point i want to add user_permissions ! How can i do this ? > > new_user.user_premissions.add('can add table_name') @ Since it is a > > manytomany field > > > > How can i set permissions from this part of code ? > > new_user.save() > > > > > > > > > > new_user.first_name = data['title'] > > new_user.email = data['email'] > > new_user.is_locked = True > > new_user.save() > > new_user.user_permissions('Can add department') > > > > profile = new_user.profile > > key = uuid.uuid4().__str__() > > profile.key = key > > profile.save() > > if new_user and profile: > > return new_user > > else: > > return False > > > > Thanks in advance > > > > > > > > Permissions are just objects, fetch them from the database and add > them to the M2M: > > >>> from django.contrib.auth.models import Permission, User > > >>> user = User.objects.get(id=1) > >>> perm = Permission.objects.get(codename='add_user') > >>> user.user_permissions.add(perm) > >>> user.user_permissions.all() > [<Permission: auth | user | Can add user>] > >>> user.has_perm('auth.add_user') > True > > Cheers > > Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Regards Nikhil Verma +91-958-273-3156 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

