Possibility to modify API response for the custom field type

Hey. I had a chance to create a custom field type using plugins. I’m wondering is there a way to modify API response for the field which has a custom type? The main idea is to have different values in a database and from UI perspective. I found a way to transform value before saving it into database (prepare_value_for_db) but I didn’t find something like this to transform it before sending API response. Is it even possible? Thanks in advance.

Hi this is very possible, you should override the following method on your custom field type and provide your own DRF serializer:

    def get_response_serializer_field(self, instance, **kwargs):
        return TODO SOME DRF SERIALIZER

Also check out all of our own field types here backend/src/baserow/contrib/database/fields/field_types.py · develop · Bram Wiepjes / baserow · GitLab and also read look over the available overridable methods with their docs on the FieldType base class here backend/src/baserow/contrib/database/fields/registries.py · develop · Bram Wiepjes / baserow · GitLab .

Got it. Thanks.
One las question here Is it possible to extend Baserow native field type with plugin or plugins allow to create new types only?

@dpetrenko it’s definitely possible. From a high level you would:

  1. Implement a new field type which extends our built in field type, with your customization implemented as overriden methods built in field type. Crucially you should not change the type property on this new class and leave it as being inheritted from the base class/
  2. In your apps.py ready method call:
# in your ready method
registry.unregister(TheBuiltInTypeYouWantToOverride)
registry.register(YourNewOverridenBuiltInType())
  1. Now, we might add new methods, change existing methods on TheBuiltInTypeYouWantToOverride with new releases of Baserow. So you might have to do some work depending on the changes when upgrading your plugin to work with a new version of Baserow.

You would do a conceptually similar process in the frontend registries also.

Thanks. What about properties? Is there an option to extend native field type with some custom properties? I’m trying to do something like this with link_row field and I face an issue “LinkRowField() got an unexpected keyword argument”. database_linkrowfield table was updated with necessary columns.

The only way I’ve found is using after_create hook and store additional options in other table. Is there a better solution?

@nigel Could you help me with the issue? Thanks in advance.