[Django] Smart Action Form prefill might not be working T-T

Feature(s) impacted

Hello Team! It is me again,

I tried the specifications on the following doc for prefilling a form on Django:

But I cannot make it work, so here are a couple of observations:

  • There is a typo on the docs since the method doesn’t have the self parameter.
  • I tried a simple operation where I try to print a message, but it is never executed.
  • I checked on the schema and the hook load is enabled.

Here are my observations:

from django_forest.utils.collection import Collection

from inventory.models import Inventory


def load_product_variants(fields, request, *args, **kwargs):
    print("Executed")
    variant = next((x for x in fields if x['field'] == 'variant'), None)

    variant['value'] = "4520"

    return fields


class InventoryForest(Collection):

    def load_product_variants_self(self, fields, request, *args, **kwargs):
        print('Executed!! Finally')
        variants = next((x for x in fields if x['field'] == 'variant'), None)

        variant['value'] = "4520"
        return fields

    def load(self):
        self.actions = [
            {
                'name': 'Assign variant',
                'fields': [
                    {
                        'field': 'variant',
                        'isRequired': True,
                        'type': 'String',
                    },
                    {
                        'field': 'quantity',
                        'isRequired': True,
                        'type': 'Number'
                    },
                ],
                'hooks': {
                    'load': self.load_product_variants_self,
                },
            }
        ]


Collection.register(InventoryForest, Inventory)

Observed behavior

I tried manipulating the self parameter on the load method without luck, adding it, removing it, and making the method static. However, when I check on the Admin UI, opening the Form never preloads any value. I also tried checking the network in case there is some request to be expected but never got any print or default value to show up.

Expected behavior

Prefilled form while using Django as the backend.

Failure Logs

Nope

Context

  • Project name: Kiara Dashboard
  • Team name: Kiara Dev Team
  • Environment name: Development
  • Agent type & version: Django 4.1.5, django-forestadmin: 1.4.4
  • Recent changes made on your end if any: Nope

Good news, I solved it myself, still a small detail on the documentation, the action itself must have a type, in my case is a single type. That solves the problem.