一名管理员管理多个站点
我有两个具有不同 SITE_ID 的网站,但我希望这两个网站只有一个管理界面。
我有一个模型,它只是一个扩展的 FlatPage:
# models.py
class SFlatPage(FlatPage):
currobjects = CurrentSiteManager('sites')
galleries = models.ManyToManyField(Gallery)
# etc
# admin.py
class SFlatPageAdmin(FlatPageAdmin):
fieldsets = None
admin.site.register(SFlatPage, SFlatPageAdmin)
admin.site.unregister(FlatPage)
我不知道为什么,但管理界面中只有当前站点的页面。在 http://site1.com/admin/ 上,我在 http://site2.com/admin/ 我看到 site2 的平面页面。但我想看到 http://site1.com/admin/ 界面中的所有页面!我做错了什么?
I have two sites with different SITE_IDs, but I want to have only one admin interface for both sites.
I have a model, which is just an extended FlatPage:
# models.py
class SFlatPage(FlatPage):
currobjects = CurrentSiteManager('sites')
galleries = models.ManyToManyField(Gallery)
# etc
# admin.py
class SFlatPageAdmin(FlatPageAdmin):
fieldsets = None
admin.site.register(SFlatPage, SFlatPageAdmin)
admin.site.unregister(FlatPage)
I don't know why, but there are only pages for current site in admin interface. On http://site1.com/admin/ I see flatpages for site1, on http://site2.com/admin/ I see flatpages for site2. But I want to see all pages in http://site1.com/admin/ interface! What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
CurrentSiteManager
。根据文档“它是一个模型管理器自动过滤其查询以仅包含与当前站点关联的对象。”拆下线路,一切都应该按预期工作。或者,如果您在代码中的其他位置使用 currobjects ,请注意管理界面始终使用指定的第一个管理器,因此您需要首先指定标准管理器,如下所示:
It's because of
CurrentSiteManager
. According to the documentation "it's a model manager that automatically filters its queries to include only objects associated with the current Site."Remove the line and everyting should work as expected. Or if you make use of
currobjects
somewhere else in your code note that admin interface always use the first manager specified, so you need to specify the standard manager first, like this: