Issue with Adding Custom Fields to Registration. (Redwood Release)

I’m working on adding custom fields to the registration form in Open edX (Redwood Release) and have run into some issues. I created a Tutor plugin to extend the registration form with additional fields. The plugin appears in the plugins list, and I can enable it successfully, but I encounter an internal server error in the browser and an error during migration.

  • Inside the tutor-plugins directory, I created a directory named reg_form_additional_fields.
  • Inside tutor-plugins, I also created a YAML file named custom_form_plugin.yml with the following content:
---
name: reg_form_additional_fields_plugin
version: 0.1.0
patches:
  lms-env: |
    "ADDL_INSTALLED_APPS": ["reg_form_additional_fields"]
    "ENABLE_COMBINED_LOGIN_REGISTRATION": true
    "REGISTRATION_EXTENSION_FORM": "reg_form_additional_fields.forms.ExtraInfoForm"

  cms-env: |
    "ENABLE_COMBINED_LOGIN_REGISTRATION": true

Inside the reg_form_additional_fields directory, I included the following files:

  • __init__.py (which is empty)
  • setup.py with the following content:
from setuptools import setup

setup(
    name='reg_form_additional_fields_plugin',
    version='1.0',
    description='OpenEdx - Custom Fields for Registration Form',
    packages=['reg_form_additional_fields'],
    install_requires=[
        'Django'
    ],
)

forms.py with the following content:

from django.forms import ModelForm
from .models import ExtraInfo

class ExtraInfoForm(ModelForm):
    """
    The fields on this form are derived from the ExtraInfo model in models.py.
    """
    def __init__(self, *args, **kwargs):
        super(ExtraInfoForm, self).__init__(*args, **kwargs)
        self.fields['email'].required = True
        self.fields['first_name'].required = True
        self.fields['last_name'].required = True
        self.fields['gender'].required = True
        self.fields['job_title'].required = True
        self.fields['organization_name'].required = True
        self.fields['organization_type'].required = True
        self.fields['primary_sector'].required = True

    class Meta:
        model = ExtraInfo
        fields = (
            'email',
            'first_name',
            'last_name',
            'gender',
            'job_title',
            'organization_name',
            'organization_type',
            'primary_sector'
        )

models.py with the following content:

from django.db import models

class ExtraInfo(models.Model):
    email = models.EmailField(max_length=255)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    gender = models.CharField(max_length=10, choices=[('male', 'Male'), ('female', 'Female'), ('other', 'Other')])
    job_title = models.CharField(max_length=100)
    organization_name = models.CharField(max_length=100)
    organization_type = models.CharField(max_length=50, choices=[('national_ngo', 'National NGO'), ('international_ngo', 'International NGO'), ('private_sector', 'Private Sector')])
    primary_sector = models.CharField(max_length=50, choices=[('wash', 'WASH'), ('health', 'Health'), ('nutrition', 'Nutrition')])

    def __str__(self):
        return f"{self.first_name} {self.last_name}"

When I run migrations, I get the following error:

Traceback (most recent call last):
  File "/openedx/edx-platform/manage.py", line 103, in <module>
    startup.run()
  File "/openedx/edx-platform/lms/startup.py", line 20, in run
    django.setup()
  File "/openedx/venv/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/openedx/venv/lib/python3.11/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/django/apps/config.py", line 193, in create
    import_module(entry)
  File "/opt/pyenv/versions/3.11.8/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'reg_form_additional_fields'