1. Florian Hahn
  2. django-object-permission-backend-nonrel

Commits

Florian Hahn  committed 9752c70

add form field for user to ObjectPermissionForm

  • Participants
  • Parent commits 0e2972f
  • Branches default

Comments (0)

Files changed (1)

File object_permission_backend_nonrel/admin.py

View file
  • Ignore whitespace
 
 class ObjectPermissionForm(BaseObjectPermissionForm):
     obj_permission_list = forms.MultipleChoiceField(required=False)
+    user = forms.ChoiceField(required=True)
 
-            
+    def __init__(self, *args, **kwargs):
+        super(ObjectPermissionForm, self).__init__(*args, **kwargs)        
+        users = User.objects.all()
+        choices = [[user.id, user.username] for user in users]
+        self.fields['user'].choices = choices
+        try:
+            self.fields['user'].initial = kwargs['instance'].user_id
+        except KeyError:
+            pass
+
     class Meta:
         model = ObjectPermission
-        exclude = ('permissions')
+        exclude = ('permissions', 'user_id')
 
 
 class BaseObjectPermissionAdmin(admin.ModelAdmin):
 admin.site.register(ObjectPermission, ObjectPermissionAdmin)
 admin.site.register(GroupObjectPermission, GroupObjectPermissionAdmin)
 admin.site.register(PermissionType, PermissionTypeAdmin)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+