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 Likes

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 Likes

This would be awesome indeed. I would like to add a custom location field to groups so that I can use the g.json output to generate a map based on the groups and amount of members.

I’ll experiment a bit with your suggestion. Do you also have some more info about how to use this snippet? Can it be used in a custom theme component? How would someone do that? Has anyone already used it?

To add custom fields to models (topics, categories, groups), the following topic from @angus really lays it out as well as you’re likely to find:

He has put together some sample code specific to topics and categories - I believe the code translates generally well for adding custom fields to groups as well.

This post from me on that topic lays out how I’ve used the resource that Angus has put together:

3 Likes