Ok, I think I've "solved" this, but my so-called solution will require a Pull Request. Here it is:
Step 1. I had to change the get_classes method in loaders.py
def get_classes(module_label, classnames):
...
# import from Oscar package (should succeed in most cases)
# e.g. 'oscar.apps.dashboard.catalogue.forms'
printif(module_label, "***********************************************")
oscar_module_label = "oscar.apps.%s" % module_label
if not (module_label.find("catalogue") >= 0 and module_label.find("dashboard") >= 0):
oscar_module = _import_module(oscar_module_label, classnames)
else:
oscar_module = None
# returns e.g. 'oscar.apps.dashboard.catalogue',
# 'yourproject.apps.dashboard.catalogue' or 'dashboard.catalogue',
# depending on what is set in INSTALLED_APPS
installed_apps_entry, app_name = _find_installed_apps_entry(module_label)
if installed_apps_entry.startswith('oscar.apps.'):
# The entry is obviously an Oscar one, we don't import again
oscar_module = _import_module(oscar_module_label, classnames)
local_module = None
# oscar_module = _import_module(oscar_module_label, classnames)
else:
...
The reason for this change is that the get_classes method imports ALL
oscar.app apps, even those that are overridden. But it seems that once you import a Form, you can't override it (at least I couldn't).
Step 2. In the my
oscarroverrides/dashboard/catalogue/forms.py file, I copied the entire
oscar.apps.dashboard.catalogue.forms.py file, and changed the
class StockRecordForm(forms.ModelForm) to make it do what I want.
I of course had to add oscaroverrides.dashboard.catalogue my get_core_apps() in settings, etc (the usual other stuff).
Here is what my oscarroverrides/dashboard/catalogue/ directory contains:
├── __init__.py
├── forms.py
└── models.py
So my question now is this: is this solution worthy of a pull request, or is there a better way?
Thanks!