Django databrowse与自定义查询? [英] Django databrowse with custom queryset?

查看:136
本文介绍了Django databrowse与自定义查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django的databrowse与django的其他部分非常不同,因为该文档的字面上不存在。有人试图在模型上做更多的databrowse.site.register吗?任何代码示例?



特别是,我有一个外部键到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆