用于多个 ModelAdmin 的管理查询集功能
在我的 admin.py 中,我有:
class SayfaAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = super(SayfaAdmin, self).queryset(request)
....
但是,我不想定义相同的查询集函数,而是希望编写一个将在管理类中调用并返回结果的函数,因此,我不想写上面的内容,而是想写:
class SayfaAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = somefunc()
def somefunc():
...
return somevalue
我的问题是,如何获得 modelAdmin 类(在我的示例中为 SayfaAdmin),以便我可以使用参数(request、self 和 modeladmin)调用该函数?
In my admin.py I have:
class SayfaAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = super(SayfaAdmin, self).queryset(request)
....
But, instead of defining same queryset function, I wish to write a function which will be called within admin class and returns the result so, instead of writing something as above, I wish to write:
class SayfaAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = somefunc()
def somefunc():
...
return somevalue
My problem is, how can I get modelAdmin class (SayfaAdmin in my example), so I can call the function with parameters (request, self and modeladmin) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不能用
self
调用它?Why can't you call it with
self
?