django admin - 选择单个模型发布到站点
嘿,我正在用 django 制作一个带有附加Shoutbox的弹出式广播播放器,但我无法获得我想要的管理功能。
我有两个模型:
1)一个流(代表管理员可以发布在首页上播放的某个广播流 - 即有多个保存的流,但一次只有一个在首页上播放,由管理员自行决定)管理员)
2)喊叫(已输入喊叫箱的喊叫,并与特定流相关联,即每个流都有由网站用户输入的多个喊叫。)
我希望管理员能够登录后端,创建多个流,但每次只能选择一个发布。据推测,每个流都应该有一个属性(即 is_published),我应该创建一个管理操作来对每个流执行检查,并仅发布正确的流?这是正确的方法还是我错过了什么
Hey, I'm making a popup radio player with an attached shoutbox with django and i'm having trouble getting the admin functionality I want.
I have two models:
1) A Stream (which represents a certain radio stream that the admin can publish to play on the frontpage - i.e. there are multiple saved streams, but only one is playing on the frontpage at a time, at the discretion of the admin)
2) A Shout (a shout that has been entered into the shoutbox, and is associated to a certain stream, i.e. every stream has multiple shouts that are entered by users of the site.)
I want the admin to be able to log into the back end, create multiple streams, but only select one to be published at any one time. Presumabley each stream should have an attribute (i.e is_published) and I should create an admin action to perform a check of every stream, and publish only the correct one? Is this the correct way to go about it or am I missing something
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我预见到的唯一潜在问题是,如果有人在管理员更改流之前已经连接并正在收听流,该怎么办?该人应该听到新的流还是继续听到他们正在听的流?
除此之外,按照你所描述的方式,我可以看到它的工作原理。您可以创建一个始终返回当前流的 url/view,例如
/stream/current/
。该 URL 的视图将始终获得最新的Stream
模型...因为您可能会在应用程序的其他地方使用“将此流设置为活动流”,所以您可以将其设为Stream 模型的一部分...
The only potential problem I forsee is, what if someone has already connected and is listening to a stream before the admin changes it. Should that person hear the new stream or continue to hear the stream they were listening to?
Other than that, the way you've described it, I could see it working. You could make a url/view which always returns the current stream, like
/stream/current/
. The view for that URL will always get the most currentStream
model...Because you're going to probably use the "set this stream as active stream" elsewhere in your app, you could make it a part of your Stream model...