Custom Fields for Groups?

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.

How would you do it?

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 出力を使用できるようにしたいと考えています。

あなたの提案で少し実験してみます。このスニペットの使用方法について、さらに詳しい情報はありますか?カスタムテーマコンポーネントで使用できますか?誰かがそれを行うにはどうすればよいですか?すでに誰かがそれを使用しましたか?

モデルにカスタムフィールドを追加するには(トピック、カテゴリ、グループ)、@angus による次のトピックが、見つけられる中で最も優れた説明となっています。

彼はトピックとカテゴリに固有のサンプルコードを作成しました。このコードは、グループにカスタムフィールドを追加する場合にも一般的にうまく機能すると考えられます。

このトピックに関する私の投稿は、Angus が作成したリソースを私がどのように使用したかを説明しています。

「いいね!」 3