开发者

Django databrowse with custom queryset?

开发者 https://www.devze.com 2023-01-18 04:29 出处:网络
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?

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 a开发者_C百科nd 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消