具有过滤查询集的组权限自定义表单
我需要提供一个用户可以管理与某个组关联的权限的方法。
我想使用来自 django 的 forms.ModelForm 功能,但我无法理解如何修改字段循环的查询集。我还深入研究了 contrib.admin 和 contrib.auth 以发现这些表单是在哪里生成的,但找不到它。
我尝试不使用普通的 modelForm,因此已经设置了先例设置。
这就是场景。我已经向我的项目添加了 40 个(或多或少)权限,所有这些权限的代号都以“xxxxx”开头,所以我想这样做:
class PermissionGroup(forms.ModelForm):
#permissions = forms.ModelMultipleChoiceField(queryset = Permission.objects.filter(codename__startswith = 'xxxxx.'), widget=forms.CheckboxSelectMultiple)
class Meta:
model = Group
fields = ('permissions',)
我怎样才能实现结果?或者如何将先例权限绑定到普通 form.ModelForm?
提前致谢!
I need to offer a from in which a user can manage the permission associated to some Group.
I'd like to use the forms.ModelForm feature which comes from django, but I cannot understand how to modify the queryset over which the field cycles. I've also taken a deep look in contrib.admin and contrib.auth to discover where those forms are generated but cannot find it.
I'm trying not to use a normal modelForm so the precedent settings are already setted.
This is the scenario. I've added 40 (more or less) permissions to my project, all them codename starts with 'xxxxx.', so I'd like to do this:
class PermissionGroup(forms.ModelForm):
#permissions = forms.ModelMultipleChoiceField(queryset = Permission.objects.filter(codename__startswith = 'xxxxx.'), widget=forms.CheckboxSelectMultiple)
class Meta:
model = Group
fields = ('permissions',)
How can I achieve the result? Or how can I bind precedent permission to a normal form.ModelForm?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)