Django databrowse与自定义查询? [英] Django databrowse with custom queryset?
问题描述
特别是,我有一个外部键到auth.Group的模型,我想要databrowse使用这个查询代替.all( ):
qs = Model.objects.filter(group__in = request.user.groups.all())
奖励积分,使得可以有一个按钮与当前对象(编辑/删除/克隆/等等) )。我基本上需要一种简单的方法来浏览和编辑行,而不让用户访问管理员。
如果有一种方法可以在管理员,但我不想给用户工作人员的特权。
没有办法通过databrowse这样做。您可以尝试为您的模型编写一个自定义管理器,并返回所需的查询集默认设置。
Django's databrowse is very different from the rest of django in that the docs literally don't exist. Has anyone tried to do more that databrowse.site.register on a model? Any code examples?
In particular, I've got a model that has a ForeignKey to an auth.Group and I want databrowse to use this queryset instead of .all():
qs = Model.objects.filter(group__in=request.user.groups.all())
Bonus points for making it possible to have a button that does stuff with the current object (edit/delete/clone/etc). I basically need a simple way to browse and edit rows without giving users access to the admin.
It'd be even better if there was a way to do that on the admin, but I don't want to give users the staff privilege.
There's no way to do this through databrowse. You could try writing a custom Manager for your Model and return the required query set by default.
这篇关于Django databrowse与自定义查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!