JQ331
1
Is it possible to create custom fields for Groups, just like we can add (and retrieve) custom fields for Users?
I have seen mention of this as a request here and there (like here).
If it’s not built into Discourse right now (it seems to me it’s not), is there a way to mimic this behavior?
2 个赞
You can do this in a plugin.
eg, in plugin.rb:
Group.register_custom_field_type('my_attribute', :boolean)
Group.preloaded_custom_fields << "my_attribute" if Group.respond_to? :preloaded_custom_fields
5 个赞
这确实很棒。我想为群组添加一个自定义位置字段,以便我可以使用 g.json 输出根据群组和成员数量生成地图。
我会尝试一下你的建议。你是否有更多关于如何使用此代码段的信息?它可以在自定义主题组件中使用吗?有人会怎么做?是否已经有人使用过它?
JQ331
6
要为模型(主题、类别、组)添加自定义字段,@angus 的以下主题非常详细地介绍了如何操作:
他为主题和类别编写了一些示例代码——我相信这些代码在为组添加自定义字段方面也具有普遍的参考价值。
我关于该主题的这篇帖子介绍了我是如何使用 Angus 提供的资源的:
3 个赞